Components

Alert Dialog

A dialog that asks one question and will not go away until it is answered: no close button, no dismissing by clicking outside, focus starts on the safe answer. For risky questions it can be taped with hazard strips and given a red patch behind its icon.

Install

terminal
npx shadcn@latest add @wobko/alert-dialog

First time here? Add the registry to components.json first. How to install

Examples

Delete (danger)

The risky question: hazard tape across the top corners, a red patch behind the icon, and a hatched destructive answer. Focus starts on Cancel.

Small

size="sm": a narrow, centered sheet with the two answers in equal columns. Good for quick confirmations.

Media tones

The round patch behind the media says what kind of question this is: highlighter for a plain confirmation, sky for information, red pencil for danger.

Async action (controlled)

A confirmation that does real work: the action keeps the dialog open while it runs (preventDefault), disables both answers, then closes it and the page reports the result.

Are you absolutely sure?

The shadcn demo with no extras: an outline trigger, a title, one paragraph and the two answers. Focus starts on Cancel, Escape closes it, a click on the backdrop does not, and focus returns to the trigger.

API reference

AlertDialogContent

The sheet: a Paper that is also the alertdialog. It takes every Radix Content prop and these.

PropTypeDefaultDescription
size"default" | "sm""default"`sm` is a narrow, centered sheet with the buttons in two equal columns.
tone"default" | "danger""default"`danger` tapes red-and-white hazard strips across the top corners.
stockStockName"paper"What the sheet is made of.
edgeEdgeSpec"cut"Cut (CSS, no svg), torn, deckle, ...
tiltboolean | numbertrueSmall seeded tilt of the sheet; text stays upright; phones lay it flat.
seedstring | number-Pins the hand.

AlertDialogMedia

The picture beside the question: put an Icon or a Sticker in it. It sits on a hand-drawn round patch.

PropTypeDefaultDescription
tone"default" | "danger" | "info""default"The patch color: highlighter, red pencil wash, sky.
seedstring | number-Pins the hand.

AlertDialogAction

The confirming answer. A Button (asChild over Radix Action) that closes the dialog after its onClick.

PropTypeDefaultDescription
variantButtonVariant"default"Any Button variant; use `destructive` for irreversible actions.
sizeButtonSize"default"Any Button size.

AlertDialogCancel

The safe answer. A Button that closes the dialog; focus starts here.

PropTypeDefaultDescription
variantButtonVariant"outline"Any Button variant.
sizeButtonSize"default"Any Button size.

Accessibility

  • Radix AlertDialog: role=alertdialog with `aria-labelledby` and `aria-describedby` (always provide a title and description). Focus is trapped, the page behind is inert, and Escape cancels.
  • Focus starts on the Cancel button, so an accidental Enter does the safe thing. Clicking outside does not dismiss it.
  • The hazard tape and the media patch are decoration; the meaning is in the words and in the destructive button (hatched, not only red).
  • With reduced motion the sheet simply appears; in `calm` density it is flat and untaped.

Source

The files the CLI copies into your project.

Loading the source