Alert Dialog
A modal that interrupts to confirm something that matters. Unlike a dialog it can't be dismissed by clicking outside: the person has to choose. Focus lands on Cancel, so a stray Enter is safe.
Install
npx shadcn@latest add @nelumbo/alert-dialogDestructive
variant='destructive' on the root makes the action a destructive button and tints the icon tile. The icon centers the header; the actions stay right-aligned (stacked full width on phones).
Nothing chosen yet.
With an icon
Without variant the tile is a neutral tonal one.
Plain
Exactly shadcn's anatomy: left-aligned text, no icon.
Usage
import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel,} from "@/components/ui/alert-dialog"<AlertDialog variant="destructive"> <AlertDialogTrigger asChild><Button variant="outline">Delete</Button></AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader icon="delete"> <AlertDialogTitle>Delete this project?</AlertDialogTitle> <AlertDialogDescription>This can't be undone.</AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Delete</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>Props
Other props go to Radix AlertDialog (open, onOpenChange, defaultOpen) and its parts.
| Prop | Type | Default | Notes |
|---|---|---|---|
AlertDialog variant | "default" | "destructive" | "default" | Destructive tints the icon tile and the action |
AlertDialogHeader icon | IconName | none | Material Symbol in a tonal tile; centers the header |
AlertDialogContent size | "sm" | "default" | "default" | Max width 22rem or 26rem |
AlertDialogAction variant | Button variant | per dialog | Also size and shape |
AlertDialogCancel variant | Button variant | "ghost" | Also size and shape |