Dialog
A dialog is a window overlaid on either the primary window or another dialog window. Content behind a modal dialog is inert, meaning users cannot interact with it.Import
Basic Usage
Sub-components
Root
Groups all parts of the dialog. Doesn’t render its own HTML element. Key Props:open(boolean): Whether the dialog is currently opendefaultOpen(boolean): Whether the dialog is initially open (default:false)modal(boolean | ‘trap-focus’): Determines if the dialog enters a modal state (default:true)true: focus is trapped, page scroll is locked, outside interactions disabledfalse: user interaction with the rest of the document is allowed'trap-focus': focus is trapped but page scroll and outside interactions are enabled
onOpenChange((open: boolean, eventDetails) => void): Event handler called when the dialog is opened or closedonOpenChangeComplete((open: boolean) => void): Event handler called after animations completedisablePointerDismissal(boolean): Determines whether the dialog should close on outside clicks (default:false)handle(DialogHandle): A handle to associate the dialog with an external triggeractionsRef(React.RefObject): A ref to imperative actions (unmount,close)
Trigger
The button that opens the dialog.Portal
Portals the dialog content to a different part of the DOM.Backdrop
The backdrop that covers the screen when the dialog is open.Popup
The container for the dialog content.Title
An accessible title for the dialog.Description
An accessible description for the dialog.Close
A button that closes the dialog.Viewport
Defines the viewport element to which the dialog is confined.Styling Example
Accessibility
- Has
role="dialog"to identify it as a dialog - Title and description are automatically linked via
aria-labelledbyandaria-describedby - Focus is automatically trapped within the dialog when modal
- The backdrop and outside elements are inert when the dialog is modal
- Pressing Escape closes the dialog (can be customized)
- Focus returns to the trigger element when the dialog closes