Overlays
Dialog
Modal dialog on the native <dialog> element for confirmations and short decisions.
- Ready
- Keyboard tested
- Screen reader not tested yet
Playground
<Dialog
trigger="Archive project"
title="Archive project?"
confirmLabel="Archive"
cancelLabel="Cancel"
>
The project moves to the archive. You can restore it there.
</Dialog>States
trigger
Usage
When to use
Use a dialog when the person has to decide something before going on: confirm a destructive action, or give one to three pieces of information, such as an email address and a role for an invitation.
When not to use
- For information the person could read on the page: put it on the page.
- For forms with more than three fields: give them their own page.
- For success messages: use InlineMessage or the dialog's successMessage.
How it works
Built on the native dialog element. The browser traps focus and makes the background inert; Esc closes the dialog and focus returns to the trigger. tone="danger" turns the confirm button red for actions that can't be undone. In form mode, confirm validates the fields first: the dialog stays open with the errors shown until everything is valid, then closes and shows the successMessage under the trigger.
Content guidelines
The title is a question that names the thing (“Withdraw request?”). The body says the consequence in one or two sentences. The confirm label repeats the verb (“Withdraw”); the cancel label says what stays (“Keep request”) or simply “Cancel”. Never “OK” or “Yes”.
Do and don’t
DoThe title names the object, the buttons say what they do. Open it to see. Don’tA generic question with OK and Cancel: people have to read the text to know what they confirm.
- Title as a question, action as a verb.
- Use form mode for one to three fields, e.g. invite by email and role.
- No forms with more than three fields in a dialog; give them their own page.
- Don't use tone="danger" for actions that can be undone; it loses its warning value.
Anatomy
- triggerSecondary button that opens the dialog.
- backdropInk at 20 % behind the dialog.
- titleh2, names the dialog.
- bodyShort content in text.secondary.
- actionsCancel (ghost) and confirm (primary, or danger with tone="danger"), right-aligned.
- summaryForm mode: InlineMessage under the trigger after a successful submit.
Examples
Confirmation
Form mode
Props
| Name | Type | Default | Description |
|---|---|---|---|
| title (required) | string | – | Title, linked with aria-labelledby. |
| children (required) | ReactNode | – | Content. |
| trigger | string | – | Label of the built-in trigger. |
| triggerVariant | "primary" | "accent" | "secondary" | "ghost" | "danger" | "secondary" | Variant of the built-in trigger; primary when opening the dialog is the main action, danger for a destructive one (with tone="danger"). |
| form | boolean | false | Form mode: confirm validates the fields inside and keeps the dialog open until they are valid. |
| action | (formData: FormData) => void | Promise<void> | – | Form mode: server action or function called with the data before the dialog closes. |
| tone | "neutral" | "danger" | "neutral" | danger turns the confirm button red; only for destructive, hard-to-undo actions. |
| successMessage | string | – | Form mode: positive message shown under the trigger after a valid submit; announced to screen readers. |
| open | boolean | – | Controlled state. |
| onOpenChange | (open: boolean) => void | – | Reports opening and closing. |
| confirmLabel | string | – | Label of the primary action. |
| cancelLabel | string | "Close" | Label of the cancel action. |
| onConfirm | () => void | – | Called after confirming. |
Tokens used
| Token | Tier | Value | Utility |
|---|---|---|---|
| dialog.backdrop | component | rgba(10,10,11,0.20) | |
| dialog.bg | component | #FFFFFF | |
| dialog.border | component | rgba(10,10,11,0.08) | |
| dialog.padding | component | 32px | |
| dialog.radius | component | 16px | |
| spacing.3 | semantic | 12px | |
| spacing.4 | semantic | 16px | |
| spacing.6 | semantic | 24px | |
| spacing.8 | semantic | 32px | |
| text.primary | semantic | #0A0A0B | |
| text.secondary | semantic | #555555 | |
| type.body.size | semantic | 16px | |
| type.heading.size | semantic | clamp(24px, 2.5vw, 32px) | |
| weight.semibold | semantic | 600 |
Accessibility
| Check | How | Status |
|---|---|---|
| axe-core rules | Automated on every npm run check, at desktop and mobile width | Runs on every build |
| Keyboard | Automated Playwright test (scripts/keyboard.mjs) | Tested |
| Screen reader | Manual | Not tested yet |
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Opens the dialog from its trigger. |
| Tab | Cycles through the dialog's controls only. |
| Esc | Closes the dialog; focus returns to the trigger. |
Semantics and focus
- Native <dialog> with showModal(): the browser provides the focus trap and the inert background.
- Title through aria-labelledby.
- Esc closes; focus returns to the trigger.
- Form mode: on an invalid confirm, focus moves to the first invalid field and its error is announced.
- The trigger has aria-haspopup="dialog".
Contrast
| Pairing | Ratio (x:1) | Minimum | Status |
|---|---|---|---|
| text.primary on surface.card | 19.79 | 4.5 | Pass |
| text.secondary on surface.card | 7.46 | 4.5 | Pass |