Modal
Accessible React modal dialog built on Radix: header icon, title, description, body, footer actions, sizes, focus trapping, and Escape to close. Inherits theme and RTL.
Modal opens a centered dialog from a trigger: header, body, and a footer of actions. It inherits theme and direction from the provider.
When to use
Use Modal for a short task that must be completed or cancelled before returning. Examples: confirming a deletion, entering a verification code, or reviewing a summary before submission. Keep it to one purpose and a few controls.
For longer secondary flows, use Drawer. For a lightweight panel anchored to a control, use Popover.
Examples
Props
Props declared by Modal. Native attributes of the underlying element pass through.
<Modal>
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ||
open | boolean | ||
defaultOpen | boolean | ||
onOpenChange | (open: boolean) => void | ||
modal | boolean |
<ModalTrigger>
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean |
<ModalClose>
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean |
<ModalContent>
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "full" | ||
centered | boolean | ||
showCloseButton | boolean | Render the corner X close button. Defaults to true. Set false for
action-forcing dialogs where the user must pick a footer action. | |
closeLabel | string | Localized label for the close button. Defaults to "Close". | |
forceMount | true | Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. | |
onOpenAutoFocus | (event: Event) => void | Event handler called when auto-focusing on open. Can be prevented. | |
onCloseAutoFocus | (event: Event) => void | Event handler called when auto-focusing on close. Can be prevented. | |
deferPointerDownOutside | boolean | When true, a 'pointerdown' event outside of the layered element will
wait for the interaction's click event before dispatching, allowing
third-party code to stop propagation of later events and cancel dismissal. | |
onEscapeKeyDown | (event: KeyboardEvent) => void | Event handler called when the escape key is down. Can be prevented. | |
onPointerDownOutside | (event: PointerDownOutsideEvent) => void | Event handler called when the a pointerdown event happens outside of the DismissableLayer.
Can be prevented. | |
onFocusOutside | (event: FocusOutsideEvent) => void | Event handler called when the focus moves outside of the DismissableLayer.
Can be prevented. | |
onInteractOutside | (event: PointerDownOutsideEvent | FocusOutsideEvent) => void | Event handler called when an interaction happens outside the DismissableLayer.
Specifically, when a pointerdown event happens outside or focus moves outside of it.
Can be prevented. | |
asChild | boolean |
<ModalHeader>
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean | ||
icon | react.ReactNode | Optional featured icon shown above the title in a 40px SDGA disc. |
<ModalTitle>
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean | Override the heading element (e.g. render an <h3> instead of the default <h2>). |
<ModalDescription>
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean | Override the element (e.g. render a <div> for richer markup). |
Accessibility
Modal is a Radix Dialog: it renders role="dialog" with aria-modal, traps focus while open, closes on Escape, and returns focus to the trigger on close. ModalTitle and ModalDescription are linked to the dialog so its name and purpose are announced.
The close button uses closeLabel as its accessible name, and the overlay inherits direction and theme from the provider.