Modal
Compose a modal trigger, backdrop, and content surface.
Use Modal when you need to compose backdrop, trigger, and content directly. Use Dialog for a structured title, description, body, and footer.
Basic usage#
Playground#
Anatomy#
Portal owns the mounted Overlay and Content subtree and preserves it through exit motion.
Usage#
Composition#
Place Modal.Overlay and Modal.Content inside the same Modal.Portal. The Portal mounts them
when open and keeps them present through exit animations. Without it, both parts render in place
and your application controls their mounting. One root owns one active Content; use a nested
Modal root for a second surface.
Use Dialog or Sheet for structured title, description, body, and footer regions. Their Content parts include a Portal internally.
Focus and outside interaction#
modal defaults to true: focus stays inside the surface, outside content is hidden from assistive
technology, and native outside pointer actions are prevented. Provide an accessible name with
ariaLabel or ariaLabelledBy on Modal.Content.
Setting modal={false} allows focus to leave, but Escape and outside interactions still request
closure according to dismissible. Scroll locking is independent: preventScroll defaults to
true. To allow background page interaction, set preventScroll={false} and omit Modal.Overlay.
Styling and portal placement#
The root renders no element. Apply class and object style to rendered parts; root classes
and styles set their slot defaults. See Customization.
Set root portalMount for a chosen container, including controlled surfaces without a Trigger.
Modal.Portal mount overrides that default.
State and exit lifecycle#
Use open with onOpenChange for controlled visibility. onExitComplete waits for the overlay and content exit animations to finish. An empty class does not disable built-in styles.
Keyboard interaction#
| Key | Description |
|---|---|
| Esc | Requests dismissal when dismissible={true}. |
| ⇥ | Moves focus forward within the modal focus scope. |
| Shift + Tab | Moves focus backward within the modal focus scope. |
Examples#
Controlled state#
Without backdrop#
Draggable title#
Exit lifecycle#
Attributes#
data-closedSlot: modal-overlay, modal-contentDescription: Present when disclosure or transition content is closed.data-expandedSlot: modal-overlay, modal-contentDescription: Present when the panel, accordion, or menu is expanded.data-overlay-scrollSlot: modal-overlayDescription: Present when scrolling is owned by the overlay.Props#
Modal#
Trigger#
Renders a <button> element by default.
Portal#
Overlay#
Renders a <div> element by default.
Content#
Renders a <div> element by default.
Close#
Renders a <button> element by default.