Skip to content

Overlays

Dialog

Modal dialog on the native <dialog> element for confirmations and short decisions.

  • Ready
  • Keyboard tested
  • Screen reader not tested yet

Updated 2026-11-12

Playground

Change the props. The controls come from the documented props.

Archive project?

The project moves to the archive. You can restore it there.
tsx
<Dialog
  trigger="Archive project"
  title="Archive project?"
  confirmLabel="Archive"
  cancelLabel="Cancel"
>
  The project moves to the archive. You can restore it there.
</Dialog>

States

Every variant in every state, side by side. Hover, pressed and focus are shown statically; the default state is interactive.

trigger

  • focus-visible

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

  • Delete the draft “Q3 report”?

    The draft and its comments are deleted. This can’t be undone.
    DoThe title names the object, the buttons say what they do. Open it to see.

    Are you sure?

    This can’t be undone.
    Don’tA generic question with OK and Cancel: people have to read the text to know what they confirm.
Do
  • Title as a question, action as a verb.
  • Use form mode for one to three fields, e.g. invite by email and role.
Don’t
  • 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

The parts of the component and what each one does, as in the playground above.
  1. triggerSecondary button that opens the dialog.
  2. backdropInk at 20 % behind the dialog.
  3. titleh2, names the dialog.
  4. bodyShort content in text.secondary.
  5. actionsCancel (ghost) and confirm (primary, or danger with tone="danger"), right-aligned.
  6. summaryForm mode: InlineMessage under the trigger after a successful submit.

Examples

Type-checked, and the same code goes into the AI manifest. Import: import { Dialog } from "@/ds";

Confirmation

Withdraw request?

The request will be deleted. This can’t be undone.

Form mode

Invite a user

Role

Props

Checked against the component's TypeScript type on every build.
Dialog props
NameTypeDefaultDescription
title (required)string–Title, linked with aria-labelledby.
children (required)ReactNode–Content.
triggerstring–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").
formbooleanfalseForm 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.
successMessagestring–Form mode: positive message shown under the trigger after a valid submit; announced to screen readers.
openboolean–Controlled state.
onOpenChange(open: boolean) => void–Reports opening and closing.
confirmLabelstring–Label of the primary action.
cancelLabelstring"Close"Label of the cancel action.
onConfirm() => void–Called after confirming.

Tokens used

Derived from the utility classes in the component's source. Copy a class with one click.
Tokens used by Dialog
TokenTierValueUtility
dialog.backdropcomponentrgba(10,10,11,0.20)
dialog.bgcomponent#FFFFFF
dialog.bordercomponentrgba(10,10,11,0.08)
dialog.paddingcomponent32px
dialog.radiuscomponent16px
spacing.3semantic12px
spacing.4semantic16px
spacing.6semantic24px
spacing.8semantic32px
text.primarysemantic#0A0A0B
text.secondarysemantic#555555
type.body.sizesemantic16px
type.heading.sizesemanticclamp(24px, 2.5vw, 32px)
weight.semiboldsemantic600

Accessibility

What is checked automatically on every build, and what a person has tested. Nothing is marked as tested unless it was.
Testing status by check
CheckHowStatus
axe-core rulesAutomated on every npm run check, at desktop and mobile widthRuns on every build
KeyboardAutomated Playwright test (scripts/keyboard.mjs)Tested
Screen readerManualNot tested yet

Keyboard

Dialog keyboard interactions
KeyAction
Enter / SpaceOpens the dialog from its trigger.
TabCycles through the dialog's controls only.
EscCloses 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

Dialog contrast pairings
PairingRatio (x:1)MinimumStatus
text.primary on surface.card19.794.5Pass
text.secondary on surface.card7.464.5Pass