Demos

A dialog that holds a short form.

Usage

Use a dialog for a short task or a decision that blocks the current flow: confirm a delete, edit a profile field. For longer forms or side content, use a Sheet. Do not open a dialog the reader did not ask for.

Import it from @workspace/ui/components/dialog.

Anatomy

  • Dialog — Holds the open state.
  • DialogTrigger — Opens the dialog.
  • DialogContent — The window, with backdrop and a close button.
  • DialogHeader — Stacks the title and description.
  • DialogTitle — Names the dialog for screen readers. Always include it.
  • DialogDescription — Supporting text.
  • DialogFooter — Actions. Stacks on small screens.
  • DialogClose — Closes the dialog. Pass a button through render.
  • DialogPortal and DialogOverlay — The portal and backdrop. DialogContent already renders both, so you rarely need them.

Notes

  • Focus moves into the dialog on open and back to the trigger on close.
  • Escape and a click on the backdrop close the dialog.
  • Put the safe action first in the footer and the destructive one last.

Examples

Confirm

Confirm a destructive action. showCloseButton={false} hides the X so the reader picks an answer.

Controlled

Hold the state with open and onOpenChange to close the dialog after an action finishes.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

Dialog

PropTypeDefaultDescription
defaultOpenbooleanfalseOpen on first render.
openboolean—Open state when controlled.
onOpenChange(open) => void—Called when the dialog opens or closes.
modalboolean or "trap-focus"trueBlock interaction with the page behind. "trap-focus" traps focus but leaves page scroll and clicks alone.

DialogContent

PropTypeDefaultDescription
showCloseButtonbooleantrueShow the X button in the corner.
classNamestring—Classes merged onto the window.

DialogFooter

PropTypeDefaultDescription
showCloseButtonbooleanfalseAdd an outline Close button.