Alert Dialog
A confirmation dialog built on Radix AlertDialog for destructive or irreversible actions. It has no close X and does not dismiss on outside click, and its action button defaults to the danger tone.


Installed with shadcn add · 2 workarounds · theme from registry.json
- applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
- installed base item https://ai2.design/r/tokens.json (registry preview settings)
Installation
pnpm dlx shadcn@latest add @ai2/alert-dialog
Requires @ai2 in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
usage.tsx
import { Button } from "@/components/ui/button"import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"<AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Delete</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you sure?</AlertDialogTitle> <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>- Confirming destructive actions such as deleting a record, revoking access, or removing a team member.
- Asking the user to confirm an irreversible operation where an accidental dismissal would be unsafe.
- Showing a required decision that should not be closed by clicking outside, unlike a general Dialog.
- Replacing window.confirm with an accessible, styled confirmation.
Examples
Delete confirmation
A destructive delete flow using the default danger tone on the action button.
delete-confirmation.tsx
import { Button } from "@/components/ui/button"import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"export function DeleteProject({ onDelete }: { onDelete: () => void }) { return ( <AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Delete</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Delete this project?</AlertDialogTitle> <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction onClick={onDelete}>Delete</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> )}Brand-tone confirmation
A non-destructive but significant confirmation that uses the brand tone on the action button.
brand-tone-confirmation.tsx
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"export function PublishConfirm({ open, onOpenChange, onPublish }: { open: boolean; onOpenChange: (open: boolean) => void; onPublish: () => void }) { return ( <AlertDialog open={open} onOpenChange={onOpenChange}> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Publish this page?</AlertDialogTitle> <AlertDialogDescription>It will be visible to all visitors.</AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Not yet</AlertDialogCancel> <AlertDialogAction tone="brand" onClick={onPublish}>Publish</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> )}Neutral-tone acknowledgement
An informational prompt with the neutral tone on the action button.
neutral-tone-acknowledgement.tsx
import { AlertDialog, AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"import { Button } from "@/components/ui/button"export function SessionNotice() { return ( <AlertDialog> <AlertDialogTrigger asChild> <Button>Show notice</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Session expiring</AlertDialogTitle> <AlertDialogDescription>Your session will end in 5 minutes.</AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogAction tone="neutral">OK</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> )}API reference
PropTypeDefaultDescription
openboolean—Controlled open state of AlertDialog (Radix AlertDialog Root prop, passed through via spread).
defaultOpenboolean—Initial open state when uncontrolled (Radix AlertDialog Root prop, passed through).
onOpenChange(open: boolean) => void—Called when the open state changes (Radix AlertDialog Root prop, passed through).
asChildboolean—On AlertDialogTrigger, merges behavior onto the child element instead of rendering a button (Radix Trigger prop, passed through).
classNamestring—Additional classes merged via cn() onto AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, and AlertDialogCancel.
tone"neutral" | "brand" | "danger""danger"Only on AlertDialogAction. Selects the solid button tone passed to buttonVariants. AlertDialogCancel has no tone prop; it is fixed to outline neutral.
childrenReact.ReactNode—Content of each subcomponent. Passed through to the underlying element.
Accessibility
- Built on Radix AlertDialog, which uses role="alertdialog" so assistive technology announces it as a modal requiring a response.
- Title and Description are wired to the content via Radix so they form the accessible name and description.
- Unlike Dialog, there is no close X button, and clicking the overlay does not dismiss it. Users must choose an action or cancel. Escape still follows Radix default behavior unless you intercept it.
- The docs state that the cancel button receives focus first, matching WAI-ARIA guidance for alert dialogs so accidental confirmation is less likely.
- Overlay and content animations are disabled under prefers-reduced-motion via motion-reduce:animate-none.
- Keep the title and description specific about the consequence so the action label is understood without relying on color alone.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
prompt.md
Use the "Alert Dialog" component (ai2/alert-dialog) from its shadcn registry.1. Install it with: npx shadcn@latest add @ai2/alert-dialog2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: open, defaultOpen, onOpenChange, asChild, className, tone, children.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { Button } from "@/components/ui/button"import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"<AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Delete</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you sure?</AlertDialogTitle> <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>```Files & dependencies
- registry/ai2/ui/alert-dialog.tsx
dependenciesradix-ui@^1.6.1tw-animate-css@^1.4.0
registryDependencies@ai2/button@ai2/tokens@ai2/primitives