overlay
A confirmation the user must answer, for destructive or important actions. Clicking outside does not close it.
npx blankui add alert-dialogtitle and description are both required. Cancel gets focus when it opens, so pressing Enter by accident does not confirm.
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogFooter,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="destructive">Delete project</Button>
</AlertDialogTrigger>
<AlertDialogContent
title="Delete this project?"
description="All files and settings will be removed. This cannot be undone."
>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction destructive onClick={deleteProject}>
Delete
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
| Avoid | Instead |
|---|---|
| window.confirm('Are you sure?') | <AlertDialog> |
| <AlertDialogAction className="bg-destructive"> | <AlertDialogAction destructive> |
| A vague title like "Are you sure?" | Name the action: "Delete this project?" |
Install with the shadcn CLI: npx shadcn add https://blank.vageshwar.dev/r/alert-dialog.json