Dialog
A modal surface for a focused task that interrupts the page, with header, body and footer parts.
Usage guidelines
- Use
Dialogfor modal content that needs focus containment and scroll locking, such as editing settings or collecting short input. UseAlertDialogonly for a destructive or must-confirm decision, andDrawerfor a side panel. - Compose
DialogHeader,DialogBodyandDialogFooterinsideDialogContent. The parts own the spacing, andDialogBodyscrolls between the header and the footer when the surface reaches the viewport height. - Every dialog has a
DialogTitle. Add aDialogDescriptionwhen a sentence of context helps before the user acts. - Use
DialogHeaderCloseButtonfor the standard corner close icon and give it anaria-label. UseDialogClosewithrenderfor footer actions such as Cancel. - Outside-press dismissal is the default. Set
disablePointerDismissalon the root only when an accidental close would throw away work the user would have to redo. - Use
DialogTriggerunder the root for a dedicated button. When a trigger lives outside the root or a menu command opens a sibling dialog, connect them withcreateDialogHandle. - Keep a dialog open while its request is pending only when closing would lose the way to see the outcome or retry. Close it on success and keep it open with the error on failure.
Anatomy
DialogContent bundles the portal, backdrop and centered popup. DialogPopup is the bare dialog element for a surface that places and dresses itself; compose it with DialogPortal, DialogBackdrop and DialogViewport.
Examples
Scrolling body
Long content scrolls inside DialogBody while the header and footer stay in place.
Closing after a request
Control open to close the dialog when an async submission succeeds. While the request is pending, onOpenChange cancels dismissal and DialogHeaderCloseButton and Cancel stay disabled so the outcome remains visible. A failed request keeps the dialog open with the error and the user's input so they can retry; the first submit on each open fails in this demo.
One dialog for a list of items
A list whose items open the same dialog renders one Dialog around the list. Each DialogTrigger carries its item as payload, and the dialog reads the payload of the trigger that opened it.
Ada Lovelace
ada@example.com
Alan Turing
alan@example.com
Grace Hopper
grace@example.com
Opening with a handle
Keep a dialog opened by a menu command or a distant trigger as a sibling and connect it with createDialogHandle. Calling open(null) opens the dialog without controlled open state, and focus returns to the menu trigger when it closes.
Keyboard
| Key | Action |
|---|---|
| EnterorSpace | Opens the dialog from a focused trigger. |
| TaborShift+Tab | Moves focus between the dialog's controls. Focus stays inside the dialog while it is open. |
| Escape | Closes the dialog and returns focus to the trigger. |
API reference
Dialog
Groups all parts of a modal dialog. Doesn't render its own HTML element.
| Prop | Type | Default | Details |
|---|---|---|---|
open | boolean | No default | |
defaultOpen | boolean | false | |
modal | 'trap-focus' | boolean | true | |
onOpenChange | ((open: boolean, eventDetails: BaseDialog.Root.ChangeEventDetails) => void) | No default | |
onOpenChangeComplete | ((open: boolean) => void) | No default | |
disablePointerDismissal | boolean | false | |
actionsRef | React.RefObject<DialogRootActions | null> | No default | |
handle | BaseDialog.Handle<Payload> | No default | |
children | PayloadChildRenderFunction<Payload> | React.ReactNode | No default | |
triggerId | string | null | No default | |
defaultTriggerId | string | null | No default | |
DialogBackdrop
An overlay displayed beneath the popup. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
forceRender | boolean | false | |
className | string | ((state: DialogBackdropState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogBackdropState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogBackdropState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the dialog is open. |
data-closed | Present when the dialog is closed. |
data-starting-style | Present when the dialog begins animating in. |
data-ending-style | Present when the dialog is animating out. |
DialogBody
Accepts the props of the element it renders.
DialogClose
A button that closes the dialog. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DialogCloseState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogCloseState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogCloseState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
DialogContent
A centered modal dialog surface bundled with a portal and backdrop. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
children required | React.ReactNode | No default | |
backdropProps | DialogBackdropProps | No default | |
className | string | ((state: DialogPopupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogPopupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogPopupState) => React.CSSProperties | undefined) | No default | |
initialFocus | boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the dialog is open. |
data-closed | Present when the dialog is closed. |
data-starting-style | Present when the dialog begins animating in. |
data-ending-style | Present when the dialog is animating out. |
data-nested | Present when the dialog is nested within another dialog. |
data-nested-dialog-open | Present when the dialog has other open dialogs nested within it. |
| Variable | Description |
|---|---|
--nested-dialogs | Values: Indicates how many dialogs are nested within. |
DialogDescription
A paragraph with additional information about the dialog. Renders a <p> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DialogDescriptionState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogDescriptionState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogDescriptionState) => React.CSSProperties | undefined) | No default | |
DialogFooter
Accepts the props of the element it renders.
DialogHeader
Accepts the props of the element it renders.
DialogHeaderCloseButton
An icon close button positioned in the corner of DialogHeader, which reserves space for it automatically. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
aria-label required | string | No default | |
style | React.CSSProperties | ((state: DialogCloseState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
DialogPopup
A container for the dialog contents. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DialogPopupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogPopupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogPopupState) => React.CSSProperties | undefined) | No default | |
initialFocus | boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the dialog is open. |
data-closed | Present when the dialog is closed. |
data-starting-style | Present when the dialog begins animating in. |
data-ending-style | Present when the dialog is animating out. |
data-nested | Present when the dialog is nested within another dialog. |
data-nested-dialog-open | Present when the dialog has other open dialogs nested within it. |
| Variable | Description |
|---|---|
--nested-dialogs | Values: Indicates how many dialogs are nested within. |
DialogPortal
A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
keepMounted | boolean | false | |
container | HTMLElement | React.RefObject<HTMLElement | ShadowRoot | null> | ShadowRoot | null | No default | |
className | string | ((state: DialogPortalState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogPortalState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogPortalState) => React.CSSProperties | undefined) | No default | |
DialogTitle
A heading that labels the dialog. Renders an <h2> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DialogTitleState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogTitleState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogTitleState) => React.CSSProperties | undefined) | No default | |
DialogTrigger
A button that opens the dialog. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
handle | BaseDialog.Handle<Payload> | No default | |
payload | Payload | No default | |
id | string | No default | |
className | string | ((state: DialogTriggerState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogTriggerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogTriggerState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-disabled | Present when the trigger is disabled. |
data-popup-open | Present when the corresponding dialog is open. |
DialogViewport
A positioning container for the dialog popup that can be made scrollable. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DialogViewportState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogViewportState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogViewportState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the dialog is open. |
data-closed | Present when the dialog is closed. |
data-starting-style | Present when the dialog begins animating in. |
data-ending-style | Present when the dialog is animating out. |
data-nested | Present when the dialog is nested within another dialog. |
data-nested-dialog-open | Present when the dialog has other open dialogs nested within it. |
createDialogHandle
Creates a new handle to connect a Dialog.Root with detached Dialog.Trigger components.
Returns
BaseDialog.Handle<Payload>| Member | Type | Description |
|---|---|---|
open required | (triggerId: string | null) => void | Opens the dialog, optionally associating it with a trigger. This method should only be called in an event handler or an effect (not during rendering). |
openWithPayload required | (payload: Payload) => void | Opens the dialog with the given payload, without associating it with any trigger. This method should only be called in an event handler or an effect (not during rendering). |
close required | () => void | Closes the dialog. This method should only be called in an event handler or an effect (not during rendering). |
isOpen required | boolean | Whether the dialog is currently open. Returns |