Dialog
Present a labeled modal task with structured content and dismissal.
Use Dialog when an action or form needs focused attention with a labeled modal surface. The trigger and content share disclosure state through the root.
Basic usage#
Playground#
Anatomy#
Content is portaled. Overlay and Content are siblings by default; scrollable overlay mode nests Content inside Overlay.
Usage#
Content composition#
Use Content title and description for simple cases:
For a custom header layout, compose the anatomy parts:
An explicit Dialog.Header replaces the header generated by Content’s title and description.
Dialog.Title and Dialog.Description connect their IDs to the surface’s accessible name and description.
Without a visible title, supply root ariaLabel or native ARIA labeling on Content.
Dialog.Action places actions beside the title. Dialog.Close is an explicit close control you can
place inside the root; it is separate from Content’s automatic corner close button.
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. Closing restores focus to the trigger.
Setting modal={false} allows focus to leave the surface, but does not disable Escape or outside
dismissal. dismissible controls those close requests. Scroll locking is independent:
preventScroll defaults to true. For interaction with the background page, also set
preventScroll={false} and overlay={false}.
Styling and portal placement#
Apply class and object style directly to each rendered part. Root classes and styles set
slot defaults for the family; Content’s slot maps cover only overlay, content, and contentClose.
See Customization for precedence.
Set root portalMount to place Content in a chosen container. This also works for controlled
surfaces without a Trigger.
Nested overlays#
Nested roots keep dismissal and focus restoration local to the active layer. Escape closes the topmost dialog or popover, then returns focus to its trigger inside the parent dialog.
State and dismissal#
Use controlled open with onOpenChange when the surrounding flow owns visibility. dismissible={false} blocks outside and Escape dismissal and calls onClosePrevent; provide a clear explicit close path in that case.
Structure and lifecycle#
Use root scrollable for long content or fullscreen for a full-viewport task. onExitComplete
runs after the overlay and content finish their exit animations.
Keyboard interaction#
| Key | Description |
|---|---|
| Esc | Requests dismissal when dismissible={true}. |
| ⇥ | Moves focus forward through focusable controls inside the dialog. |
| Shift + Tab | Moves focus backward through focusable controls inside the dialog. |
Examples#
Destructive confirmation#
Keep the item visible until the user confirms the action. Cancel and backdrop dismissal leave it intact.
Scrollable and fullscreen content#
Controlled lifecycle#
Attributes#
data-closedSlot: dialog-trigger, dialog-content, dialog-overlayDescription: Present when disclosure or transition content is closed.data-disabledSlot: dialog-triggerDescription: Present when the component, slot, or item is disabled.data-expandedSlot: dialog-trigger, dialog-content, dialog-overlayDescription: Present when the panel, accordion, or menu is expanded.data-overlay-scrollSlot: dialog-overlayDescription: Present when scrolling is owned by the overlay.data-footerSlot: dialog-bodyDescription: Present when the component renders footer content.data-headerSlot: dialog-bodyDescription: Present when the component renders header content.data-scrollSlot: dialog-bodyDescription: Present when the content region owns scrolling.Props#
Dialog#
Trigger#
Renders a <button> element by default.
Content#
Props for Dialog.Content. Renders a <div> element by default.
Header#
Renders a <div> element by default.
Title#
Renders a <h2> element by default.
Description#
Renders a <p> element by default.
Action#
Renders a <div> element by default.
Body#
Renders a <div> element by default.
Footer#
Renders a <div> element by default.
Close#
Renders a <button> element by default.