Dialog
A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.
Features
Supports modal and non-modal modes.
Focus is automatically trapped within modal.
Can be controlled or uncontrolled.
Manages screen reader announcements with
TitleandDescriptioncomponents.Esc closes the component automatically.
Anatomy
Import all parts and piece them together.
For a custom trigger, asChild takes a target factory, not an already-created JSX child.
The target attaches the primitive's props, ref, and event composition to the selected host.
API Reference
Root
Contains all the parts of a dialog.
Trigger
The button that opens the dialog.
Portal
When used, portals your overlay and content parts into the body.
Overlay
A layer that covers the inert portion of the view when the dialog is open.
Content
Contains content to be rendered in the open dialog.
Close
The button that closes the dialog.
Title
An accessible title to be announced when the dialog is opened.
If you want to hide the title, use our Visually Hidden utility: <VisuallyHidden.Root asChild>{target => target(Dialog.Title, { children: "Title" })}</VisuallyHidden.Root>.
Description
An optional accessible description to be announced when the dialog is opened.
If you want to hide the description, use our Visually Hidden utility: <VisuallyHidden.Root asChild>{target => target(Dialog.Description, { children: "Description" })}</VisuallyHidden.Root>. To remove the description entirely, omit this part and pass aria-describedby={undefined} to Dialog.Content.
Examples
Close after asynchronous form submission
Use the controlled props to programmatically close the Dialog after an async operation has completed.
Scrollable overlay
Move the content inside the overlay to render a dialog with overflow.
Custom portal container
Customise the element that your dialog portals into.
Accessibility
Adheres to the Dialog WAI-ARIA design pattern.
Keyboard Interactions
Custom APIs
Create your own API by abstracting the primitive parts into your own component.
Abstract the overlay and the close button
This example abstracts the Dialog.Overlay and Dialog.Close parts.