Live example

Usage
<Dialog
  open={open}
  onOpenChange={setOpen}
  title="New booking"
  footer={<Button variant="primary" type="submit" form="booking">Save</Button>}
>
  <form id="booking">...</form>
</Dialog>

Props

Dialog props
PropTypeDefaultDescription
openbooleannoneWhether the dialog is shown.
onOpenChange(open: boolean) => voidnoneCalled with false on Escape, backdrop click or close.
titleReactNodenoneHeading that names the dialog.
description?ReactNodenoneShort text that describes the dialog.
footer?ReactNodenoneActions. Put the primary action last.
initialFocus?RefObject<HTMLElement>noneElement to focus on open. Defaults to the first field.
role?'dialog' | 'alertdialog''dialog'alertdialog for confirmations; it ignores backdrop clicks.
size?'sm' | 'md' | 'lg''md'Maximum width.

Do and don't

Do

  • Use for short, focused tasks such as creating a record.
  • Give every dialog a clear title and a visible way to close.

Don't

  • Open a dialog from a dialog.
  • Use a dialog for content people need to compare with the page behind.

Accessibility

  • role dialog with aria-modal, named by the title and described by the description.
  • The rest of the page gets the inert attribute, so screen reader virtual cursors cannot leave the dialog.
  • Focus moves to the first field on open and returns to the trigger on close. Body scroll is locked.

Keyboard

Dialog keyboard support
KeysAction
Tab, Shift + TabCycle through controls inside the dialog only
EscapeCloses the dialog