Dialog
Dialog shows a panel over a dimmed page for a short task that needs a person's full attention.
<Dialog> <DialogTrigger render={<Button>Rename project</Button>} /> <DialogContent> <DialogTitle>Rename project</DialogTitle> <DialogDescription> Everyone with access sees the new name. </DialogDescription> <DialogClose render={<Button emphasis="loud">Save</Button>} /> </DialogContent></Dialog>Use a Dialog for a short task that must be finished or cancelled before a person goes back to the page, such as editing settings or renaming a project. To ask a yes-or-no question before a risky action, use AlertDialog. For a small panel that leaves the page usable, use Popover. For a panel attached to an edge of the window, use Sheet.
The panel looks like a Card with a slightly rounder corner, and the page behind it is dimmed. In a theme with depth="elevated" it has the same shadow as a Card, and nothing more, because the dimmed page already shows that the dialog is on top. On a narrow window the panel is attached to the bottom edge of the screen instead of being centred.
Write the layout inside the panel yourself with Stack and Flex. size sets the panel's maximum width, padding and corner, and the text size of DialogTitle and DialogDescription. Any other text you add keeps its own size. There is no close button in the corner, so put a DialogClose button where your layout needs one.
Put the title in the panel's Toolbar beside Close, or write the DialogTitle as the next row under a Toolbar that holds only Close. Under the toolbar, the dialog places the title one small step below it and a DialogDescription one small step below the title, so you add no space between them.
The panel grows with its content. To limit its height, set maxHeight in the style of DialogContent and put a ScrollArea inside, so the long content scrolls while the title and the buttons stay in view.
Open a dialog with DialogTrigger, or control it with open and onOpenChange. onOpenChange receives the reason for closing, such as escape-key or outside-press, and you can call cancel() to keep the dialog open, for example while a person has unsaved text.
When the dialog opens, focus moves into the panel and Tab stays inside it. Escape or a press outside the panel closes it, and focus then returns to the trigger. A screen reader announces the dialog by its DialogTitle and reads the DialogDescription with it, so always include a title.
The part names follow shadcn/ui's dialog (MIT), and the behaviour comes from Base UI's Dialog.
- Popover when the task is small and the page should stay usable around it.
- Alert Dialog when the person must answer before going on, such as confirming a loss that cannot be undone. If the action can be undone, do it and offer undo instead of asking.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
Opening the dialog
Dialog
Dialog shows a panel over a dimmed page for a short task that needs a person's full attention.
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The DialogTrigger and the DialogContent, in either order. |
defaultOpen? | boolean | Uncontrolled starting state. |
onOpenChange? | (open: boolean, details: OverlayOpenChangeDetails) => void | Called when the dialog opens or closes. |
open? | boolean | Controlled open state. |
size? | "1" | "2" | "3" | "4" | Sets the size step of the panel: its maximum width, padding and corner. |
DialogTrigger
The button that opens the dialog, usually render={<Button />}. If your own state opens the dialog, you don't need a trigger
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The button's label. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
nativeButton? | boolean | Tells the part if the rendered element is a real <button>. |
render? | RenderElement | Usually a Kookie Button: <DialogTrigger render={<Button/>}>Delete…</DialogTrigger>. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <button>.
Showing the panel
DialogContent
The panel. It renders in a portal with your theme settings, dims the page and centres itself. If the panel is taller than the window, the area around it scrolls
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The panel's content. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <div>.
Naming the dialog
DialogTitle
The heading of the dialog and its accessible name. It renders a heading element, sized by the dialog's size
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The dialog's name. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <h2>.
DialogDescription
A line of supporting text in the muted text colour. A screen reader reads it after the title
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The supporting text: what the dialog asks for. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <p>.
Closing the dialog
DialogClose
A button that closes the dialog. Place it in your layout beside the other actions, usually with render={<Button />}
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The button's label. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
nativeButton? | boolean | Tells the part if the rendered element is a real <button>. |
render? | RenderElement | Usually a Kookie Button: <DialogTrigger render={<Button/>}>Delete…</DialogTrigger>. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <button>.
DialogHeaderandDialogFooter— A header and a row of actions are layout, so write them withStackandFlex.DialogTitleandDialogDescriptionexist because a screen reader needs them to name the dialog.- A prop to choose the presentation, and dragging to close — The window width decides whether the panel is centred or attached to the bottom edge, and it stays the same element either way. Dragging would need code running on every pointer move.
- A height prop — The panel grows with its content. To limit it, set
maxHeightin thestyleofDialogContentand put aScrollAreainside. - A close button in the corner — Escape and a press outside the panel already close the dialog. Put a
DialogClosebutton wherever your layout needs one, usually beside the other actions. modalanddisablePointerDismissal— A dialog always keeps focus inside it and stops the page from scrolling. For a panel that leaves the page usable, usePopover. To stop an outside press from closing it, useAlertDialog.- A shadow of its own — The dimmed page already shows that the dialog is on top. In a theme with
depth="elevated"the panel has the same shadow as aCard. sizeon the title — The dialog'ssizesets the size of the title and the description, so they always match the panel. Other text that you add keeps its own size.