When to use
- Focused tasks: Short forms, template selection and quick settings adjustments.
- Secondary content: Image zoom-ins, detailed information, video playback.
When to use something else
- Non-blocking messages that don’t require immediate action: use Sonner, Banner, or Alert (context-dependent).
- Important messages requiring immediate attention or blocking confirmation: use Alert dialog.
- Comparative workflows: use a drawer or side panel if the user must compare information without losing surrounding context.
- Complex or multi-step flows: use a dedicated page or wizard if the input is too heavy for a Dialog.
- No need to interrupt flow: use inline patterns such as Accordion or Collapsible.
Alert dialog vs Dialog
A Dialog is a flexible, interactive modal used for routine tasks like editing forms, viewing detailed information, or completing multi-step workflows. An Alert dialog is an interruptive, high-priority modal specifically designed for critical or destructive decisions (such as deleting data), halting user workflow until an explicit choice is made.Dos and don’ts
- Do ensure users can easily dismiss the Dialog. Always include a cancel Button and close icon Button.
- Do trap focus within the Dialog for accessibility. Users should not be able to interact with the background content.
- Do include top and bottom Separators only if the content within the Dialog is scrollable.
- Do maintain the default center placement for all Dialogs. Alternative placements should be avoided unless there is a specific, justified use case.
- Do use a transparent overlay background behind the Dialog.
- Don’t interrupt the user unnecessarily - only use Dialogs when it’s important to interrupt.
- Don’t change the position of the primary call to action. It should always be positioned furthest right.
- Don’t stack multiple Dialogs or nest them.
- Don’t use a Dialog size that’s larger than necessary. There should not be a ton of white space around form or text elements.
Behavior
- Dialog variant blocks interaction with the page behind it until dismissed; focus is trapped inside the dialog while open.
- Escape and an explicit dismiss control (cancel, close) should return focus to a sensible element (typically the trigger).
- Only one Dialog should stack at a time; do not nest Dialogs.
Often used with
Footer Buttons (primary right); Separator for scrollable bodies; form fields (Input, Select, Textarea, etc.); optional inner Tabs for rare complex modals.Accessibility
Labeling and semantic markup
- Keep DialogTitle rendered: If your design omits a visual header, wrap
<DialogTitle>in an accessibility class (e.g.,className="sr-only") rather than removing the element. - Provide or explicitly suppress DialogDescription: If your dialog lacks body text, pass
aria-describedby={undefined}to<DialogContent>to prevent browser console warnings and avoid broken ARIA references. - Label icon-only triggers: If
<DialogTrigger>wraps an icon-only button, ensure the button carries an explicitaria-labelor accessible name.
Focus and flow management
- Override destructive initial focus: By default, focus moves to the first focusable element inside the content. For dangerous actions, override initial focus to target the safest action (e.g., “Cancel”) by calling
e.preventDefault()insideonOpenAutoFocusand focusing the designated element. - Handle deleted triggers on close: If closing the dialog deletes the original trigger element (e.g., deleting a table row item), focus will drop to
<body>. UseonCloseAutoFocusto direct focus to a logical fallback, like the table container or next list item. - Form error focus: If the dialog contains a form that fails validation, explicitly shift focus to the first invalid field or an error summary banner so screen reader users are notified instantly.