Installation
npx logic2b@next 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>
Usage notes
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.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
Generated JSX
<AlertDialog>
<AlertDialogTrigger
className="rounded-md border px-4 py-2 text-sm font-medium"
>Delete release</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete this release?</AlertDialogTitle>
<AlertDialogDescription>This action permanently removes the release artifacts.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction>Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>API reference
Generated from the public TypeScript exports in src/ui/alert-dialog.tsx.
AlertDialog
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Root>AlertDialogPortal
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Portal>AlertDialogOverlay
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>AlertDialogTrigger
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>AlertDialogContent
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Content>AlertDialogHeader
ComponentProps: React.ComponentProps<"div">AlertDialogFooter
ComponentProps: React.ComponentProps<"div">AlertDialogTitle
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Title>AlertDialogDescription
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Description>AlertDialogAction
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Action>AlertDialogCancel
ComponentProps: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>Accessibility contract
Machine-readable behavior and consumer responsibilities for alert-dialog.
- Support
- Primitive-managed
- Pattern
- alertdialog
- Radix Alert Dialog
| Keys | Behavior |
|---|---|
| Escape | Close the open surface and restore focus. |
| Tab Shift+Tab | Move between confirmation actions. |
Built-in semantics
- Uses alertdialog semantics, traps focus and requires an explicit action.
Consumer responsibilities
- Describe the consequence and give destructive/escape actions unambiguous labels.