Skip to content

Dialog

A modal overlay that traps focus and interrupts the user's workflow for important tasks or confirmations.

  • stable
  • since v0.1.0
  • 3.5 kB
  • overlay
  • modal
  • accessible

Uses role="dialog" aria-modal="true"; focus is trapped inside; Esc closes by default; backdrop click closes by default.

Preview
Open
tsx

Use closeOnOverlayClick={false} and a danger-coloured confirm button for destructive actions that require deliberate intent.

Preview
Open
tsx

Embed form controls inside DialogContent. Disable the submit button until input is valid to prevent empty submissions.

Preview
Open
tsx

Six sizes are available: xs, sm, md (default), lg, xl, and full. Each sets a different max-width for the content panel.

Preview
Open
tsx
PropTypeDefaultDescription
size
"xs"|"sm"|"md"|"lg"|"xl"|"full"
md
Visual size variant. `md` works for most confirm/edit flows; `lg`/`xl` are for forms; `sm` for compact confirmations.
position
"center"|"top"
center
Vertical placement. `center` for the standard modal feel; `top` anchors near the top of the viewport.
closeOnOverlayClick
boolean
true
Close when the backdrop is clicked.
closeOnEscape
boolean
true
Close when `Esc` is pressed.
showCloseButton
boolean
true
Render the built-in close button (top-right X).
container
HTMLElement|(() => HTMLElement)
Portal target.
closeLabel
string
Close
Accessible label applied to the built-in close button.
hideOverlay
boolean
false
Skip rendering the backdrop. Useful when stacking dialogs or when the parent already provides a scrim.
  • DialogContent sets role="dialog" and aria-modal="true" automatically, and wires aria-labelledby / aria-describedby from the DialogTitle and DialogDescription IDs.
  • Focus is trapped inside the dialog while it is open; it returns to the trigger on close.
  • Pressing Esc closes the dialog by default (closeOnEscape={true}); suppress with closeOnEscape={false}.
  • Clicking the backdrop closes the dialog by default (closeOnOverlayClick={true}); suppress with closeOnOverlayClick={false}.
  • DialogTitle maps to aria-labelledby; DialogDescription maps to aria-describedby — both are required for complete accessible markup.
  • For non-destructive confirmations, prefer AlertDialog which is pre-wired for a single confirm/cancel axis.
  • Use position="top" to render the panel near the top of the viewport on long pages.
  • Use hideOverlay when stacking dialogs so only the outermost backdrop is visible.
  • Wrap the trigger in Tooltip to add a hover label when the trigger is icon-only.