Dialog
A window over the page that takes attention until people finish or close it.
In Accessible first
See it live
npm run storybookWhen to use it
In Accessible first: Only to confirm leaving with unsaved answers.
- Use it when: People must decide or finish something before going back: a short form, an important choice.
- Not when: A short status (toast), extra detail on the page (accordion), or a side panel that should not block the page (sheet).
Instead:
- Sheet: A side panel; the page stays in view.
- Toast: Does not interrupt.
- Alert dialog: Confirms something that cannot be undone.
How Accessible first uses it
Words
- Use common words. Explain any term you must use.
- One idea per sentence. Put the action first.
- Never blame the person.
- Use: Continue, Change, Start, You. Avoid: Invalid, Utilise, Submit, Error code.
The labels components use, from the voice tokens:
content.action.commit: Continuecontent.action.cancel: Go backcontent.action.destroy: Deletecontent.action.retry: Try againcontent.action.empty-action: Start a new application
See Voice and tone for the whole voice.
Accessibility and keyboard
| Keyboard | What happens | Not |
|---|---|---|
| undefined | Escape closes it. | undefined |
| undefined | Tab stays inside while it is open. | undefined |
Test before you ship:
- It is a dialog with a title; the page behind is hidden from screen readers. undefined
- Focus moves in when it opens and back to the trigger when it closes. undefined
Use it in code
npx open-ds add dialog
The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.
Tokens it reads
Dialog reads 20 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Dialog's tokens to change Dialog alone.
Accessible first decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.
| Part | Its token and the semantic it aliases | Value |
|---|---|---|
| Shared | ||
| Overlay background Changes with theme | component.overlay.backgroundcolor.surface.raisedvar(--overlay-background) | Lightgray.light.0:#FFFFFFDarkgray.dark.100:#222222 |
| Overlay radius | component.overlay.radiusradius.containervar(--overlay-radius) | radius.8:0.5rem |
| Overlay shadow | component.overlay.shadowelevation.overlayvar(--overlay-shadow) | shadow.none:0px 0px 0px 0px #00000000 |
| Overlay scrim Changes with theme | component.overlay.scrimcolor.surface.scrimvar(--overlay-scrim) | Lightblack.light.scrim:#0000008CDarkblack.dark.scrim:#000000B3 |
| Content | ||
| Gap | component.dialog.content.gapspace.gap.groupvar(--dialog-content-gap) | space.32:2rem |
| Padding | component.dialog.content.paddingspace.inset.containervar(--dialog-content-padding) | space.24:1.5rem |
| Text Changes with theme | component.dialog.content.labelcolor.text.primaryvar(--dialog-content-label) | Lightgray.light.900:#141414Darkgray.dark.900:#F7F7F7 |
| Dialog | ||
| Border width | component.dialog.border-widthborder-width.defaultvar(--dialog-border-width) | border-width.2:2px |
| Border Changes with theme | component.dialog.bordercolor.border.defaultvar(--dialog-border) | Lightgray.light.200:#D6D6D6Darkgray.dark.100:#222222 |
| Corner | component.dialog.radiusradius.badgevar(--dialog-radius) | radius.4:0.25rem |
| Padding | component.dialog.paddingcomponent-spacing-map.x1var(--dialog-padding) | space.4:0.25rem |
| Text Changes with theme | component.dialog.labelcolor.text.secondaryvar(--dialog-label) | Lightgray.light.700:#333333Darkgray.dark.600:#B4B4B4 |
| Sunken Changes with theme on hover | component.dialog.sunkencolor.surface.sunkenvar(--dialog-sunken) | Lightgray.light.100:#EDEDEDDarkgray.dark.100:#222222 |
| Size | component.dialog.sizesize.iconvar(--dialog-size) | size.20:1.25rem |
| Gap | component.dialog.gapspace.gap.tightvar(--dialog-gap) | space.12:0.75rem |
| Gap 2 | component.dialog.gap-2space.gap.defaultvar(--dialog-gap-2) | space.16:1rem |
| Font family | component.dialog.font-familytype.heading.font-familyvar(--dialog-font-family) | font.family.atkinson-hyperlegible:"Atkinson Hyperlegible", Verdana, sans-serif |
| Text size | component.dialog.font-sizetype.heading.font-sizevar(--dialog-font-size) | font.size.22:1.375rem |
| Weight | component.dialog.font-weighttype.heading.font-weightvar(--dialog-font-weight) | font.weight.700:700 |
| Font size 2 | component.dialog.font-size-2type.body.font-sizevar(--dialog-font-size-2) | font.size.19:1.1875rem |