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.
Dialog.Content sets aria-labelledby to Dialog.Title and aria-describedby to Dialog.Description using IDs that Dialog.Root allocates up front, so it never inspects its children. Passing aria-labelledby or aria-describedby to Content replaces that default. Passing either one as undefined removes that relationship. A nonblank aria-label names Content instead of the title, while an undefined or empty aria-label keeps the title. A Title or Description with its own id isn't linked automatically: pass the same ID to Content, e.g. <Dialog.Content aria-labelledby="profile-title"> with <Dialog.Title id="profile-title">.
Breaking in 0.1.0-rc.2: Content no longer collects part IDs or appends them to the relationships you pass. Add Content ARIA for custom part IDs, list the title ID yourself when combining it with an external label, and pass aria-describedby={undefined} when there is no Description.
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>. A custom id replaces the Root ID, so link it with aria-labelledby on Dialog.Content.
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. A custom id replaces the Root ID, so link it with aria-describedby on 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.