Overlays
Dialog
A modal surface for decisions that need attention.
Usage
Compose Dialog, a trigger and the content. It is built on the native <dialog>, so the top layer, focus containment and an inert page come from the browser. It opens with the soft rise and closes with a quick fade.
When to use
- A decision or short task that must be finished or cancelled before going on.
- Confirming something destructive (use role="alertdialog").
Not for: long forms or browsing (use a page or a sheet), non-blocking messages (use a toast), small contextual info (use a popover).
Confirmation
For destructive actions use role="alertdialog" with dismissible={false}: Esc and the backdrop no longer close it, so the person has to choose. This example is controlled and keeps the dialog open while the delete runs.
Long content
Give the body a max height and let it scroll; the header and footer stay put.
API
Dialog
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | — | Controlled open state. |
| defaultOpen | boolean | false | Initial state when uncontrolled. |
| onOpenChange | (open: boolean) => void | — | Called when the dialog asks to open or close. |
DialogContent
| Prop | Type | Default | Description |
|---|---|---|---|
| size | 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'md' | Panel width: 384 / 512 / 672 / 896px or full. |
| dismissible | boolean | true | Close on Esc and on a backdrop click. |
| showClose | boolean | true | The × button in the corner. |
| centered | boolean | false | Stay centred on phones instead of docking to the bottom. |
| role | 'dialog' | 'alertdialog' | 'dialog' | Use alertdialog for confirmations. |
| panelClassName | string | — | Classes for the card. className styles the overlay layer. |
DialogTrigger and DialogClose are buttons; pass asChild to use your own. DialogHeader, DialogTitle, DialogDescription, DialogBody and DialogFooter are layout parts.
Keyboard
| Key | Action |
|---|---|
| Esc | Closes the dialog (unless dismissible is false). |
| Tab | Moves focus to the next element inside the dialog. |
| Shift + Tab | Moves focus to the previous element inside the dialog. |
Accessibility
- Follows the WAI-ARIA modal dialog pattern; the page behind is inert.
- The title and description are wired to aria-labelledby / aria-describedby when present.
- Focus moves to the first [autofocus] field, otherwise the panel, and returns to the trigger on close.
- Page scroll is locked while open, without layout shift from the scrollbar.
Motion
- Open: the overlay fades in (220ms) while the panel rises 8px, scales from .96 and un-blurs (380ms, ease-out).
- Close: both fade out in 160ms; the dialog unmounts only after the animation ends.
- Phones: the panel docks to the bottom edge and rises 24px.
- Reduced motion: it appears and disappears without movement.