Installation
npx logic2b@latest add alert-dialogUsage
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
<AlertDialog>
<AlertDialogTrigger>Delete account</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction>Continue</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
API
| Prop | Type | Default |
|---|---|---|
open / defaultOpen (AlertDialog) |
boolean — controlled/uncontrolled open state |
— |
onOpenChange (AlertDialog) |
(open: boolean) => void |
— |
asChild (AlertDialogTrigger / Action / Cancel) |
boolean |
false |
AlertDialogAction and AlertDialogCancel render with the default and outline button variants respectively — pass className to restyle (e.g. a destructive action).
Examples
Destructive action
Style the confirm button as destructive for irreversible operations.
Controlled
Open the dialog from your own state with open and onOpenChange.
Accessibility
- Follows the WAI-ARIA Alert Dialog pattern and traps focus while open.
- Opening moves focus to the dialog; closing returns it to the trigger.
- Escape closes the dialog and fires
AlertDialogCancel. Unlike a plain dialog, clicking the overlay does not dismiss it — a response is required. - The content is labelled by
AlertDialogTitleand described byAlertDialogDescription.