Alert Dialog
Asks people to confirm an action that matters, such as deleting something. The default size is 512px wide; the small size is 320px and centered. Buttons are 44px.
Installation
npx shadcn@latest add @sevenone/alert-dialogUsage
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogMedia,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"Examples
Default
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="outline">Show dialog</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete your account.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction>Continue</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>With an icon
<AlertDialogHeader>
<AlertDialogMedia>
<CircleAlert aria-hidden="true" />
</AlertDialogMedia>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>…</AlertDialogDescription>
</AlertDialogHeader>Small and destructive
size="sm" centers the content and puts the buttons side by side. Use the destructive variant for the action when it deletes something.
<AlertDialogContent size="sm">
<AlertDialogHeader>
<AlertDialogMedia>
<Trash2 aria-hidden="true" />
</AlertDialogMedia>
<AlertDialogTitle>Delete project?</AlertDialogTitle>
<AlertDialogDescription>You cannot undo this.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction variant="destructive">Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>Accessibility
- It does not close when people click outside: they must choose Cancel or the action. Esc works as Cancel.
- Focus starts on Cancel, so pressing Enter by accident never confirms the action.
- Write the action as a verb (Delete, Continue) and say what will happen in the description.