Dialog
A modal surface for a focused task or a decision, with a title, content and actions, or full screen on compact windows.
import { Dialog, DialogTrigger, DialogTitle, DialogHeader, DialogContent, DialogActions } from '@windmorph/react';Keyboard
| Key | Action | Where |
|---|---|---|
| Tab or Shift + Tab | Moves focus between the dialog's controls. Focus is contained: it wraps within the dialog and never reaches the page behind. | |
| Escape | Closes the dialog, unless closedBy="none". | |
| Arrow Up or Arrow Down or Page Up or Page Down | Scroll DialogContent when it is taller than the dialog and has focus. Tab reaches it after the controls before it.In scrolling content | In scrolling content |
Screen reader
- Role
alertdialogfor a basic dialog (the default), ordialogwhenfullScreenis not"never".roleoverrides either.- Accessible name
DialogTitleorDialogHeader, througharia-labelledby, oraria-labelwhen there is no visible title.- States announced
- Modal: the page behind is hidden from assistive tech while the dialog is open. An alert dialog is described by its
DialogContent(aria-describedby), and the reference is left out when there is none.
- The
iconabove the title and the scrim are decorative and hidden from assistive tech (aria-hidden). - Inside a
DialogTrigger, the trigger announces that it opens a dialog (aria-haspopup="dialog") and whether it is open (aria-expanded), and points at the open dialog (aria-controls). - In full screen with a header action,
DialogActionsare hidden (display: none), so they leave the accessibility tree and each action is announced once. On wider windows afullScreen="compact"dialog hides the header's close button the same way.
Focus
- On open, focus moves to the dialog's first interactive element, or to an element marked
autoFocus. With no controls, the dialog itself takes focus. - While
DialogContentscrolls it is focusable, with a focus ring, so the keyboard can scroll it; initial focus still skips it and goes to the first control. - On close, focus returns to the element that opened it, such as the
DialogTriggerbutton. - When the actions stack (M3: "Confirming actions appear above dismissive actions"), they are rendered in that order, so Tab and screen readers go top to bottom: the confirming action first. On one line they keep their source order, the dismissive action first. When the actions are the first controls, initial focus goes to the dismissive action, the least destructive choice (the WAI-ARIA alert dialog pattern): the first one on one line, the bottom one when stacked.
Touch target
None. The dialog has no target of its own. Its actions are Buttons and the full-screen close button is a 48 × 48px IconButton, each with its own touch target.
Motion
Under reduced motion the dialog only fades: the slide, the container's growth, the scale of transition="scale" and the full-screen container transform from its origin are dropped. instant turns every motion off, including the fades.
What you need to do
- Name every dialog with a
DialogTitle(orDialogHeader), or witharia-labelwhen there is no visible title. - Put the supporting text in
DialogContent, so an alert dialog is described by it. - Translate
DialogHeader'slabels.close("Close"), which names the full-screen close button. - Keep the default alert dialog for decisions that must be made, and pass
role="dialog"orclosedBy="any"when pressing outside may close it. - Use at most two actions, with the confirming action last. In development
DialogActionswarns once when it holds more.