Skip to content

Alert dialog

A confirmation dialog on Base UI AlertDialog.

For a decision the person has to make before anything else, such as deleting something. A click outside does not close it.

Default

Small

With media

Installation

npx shadcn@latest add @khaeli/alert-dialog

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • @base-ui/react ^1.7.0

Keyboard

EnterSpace
On the trigger, opens the dialog. Focus moves to the first button in the footer, so put the safe choice first: AlertDialogCancel.
TabShift Tab
Move between the buttons and wrap at either end. Focus cannot leave the dialog while it is open.
Escape
Closes the dialog, as Cancel does, and returns focus to the trigger.

Accessible name

  • The dialog has the role alertdialog. It is named by AlertDialogTitle and described by AlertDialogDescription: write the consequence in the description, because it is read out when the dialog opens.
  • AlertDialogAction is a plain button and does not close the dialog. Close it yourself when the action has run, as the examples do with open and onOpenChange.
  • Name the action by what it does (Delete project), not OK or Yes.
  • The icon in AlertDialogMedia is decoration: the title carries the meaning.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/alert-dialog.json