Skip to content

AlertDialog

A focus-trapping modal that interrupts the user to confirm an important or destructive action.

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

Uses role="alertdialog" aria-modal="true"; focus is trapped; cannot be dismissed by Esc or backdrop click — only via AlertDialogAction or AlertDialogCancel.

Preview
Open
tsx

Drive the open state externally with open / onOpenChange to gate confirmation on async work or to coordinate with other UI.

Preview
Open
tsx

AlertDialogContent accepts the same six sizes as Dialog: xs, sm (default), md, lg, xl, full. Keep confirmations small — there is rarely a need to go beyond sm.

Preview
Open
tsx

Pass position="top" to anchor the panel near the top of the viewport — useful on long pages where the user may have scrolled far from the trigger.

Preview
Open
tsx
PropTypeDefaultDescription
size
"xs"|"sm"|"md"|"lg"|"xl"|"full"
sm
position
"center"|"top"
center
container
HTMLElement|(() => HTMLElement)
hideOverlay
boolean
false
  • AlertDialogContent renders with role="alertdialog" and aria-modal="true", sharing the same focus-trap + scroll-lock kit as Dialog.
  • Focus is trapped inside the dialog while open and returned to the trigger on close.
  • Backdrop clicks never dismiss; Esc is also suppressed — the user must hit AlertDialogAction or AlertDialogCancel.
  • AlertDialogTitle maps to aria-labelledby; AlertDialogDescription maps to aria-describedby — both are required for a complete accessible name.
  • Default focus lands on the cancel action, making accidental confirmation unlikely.
  • Reserve AlertDialog for destructive or non-reversible choices. For everything else, use Dialog.
  • Pair the destructive action with colorScheme="danger" to reinforce the intent visually.
  • Keep the body copy short — one or two sentences naming the consequence.
  • Use the controlled pattern when the action is async — disable the button and close on success.