Are you absolutely sure?
This action cannot be undone. This will permanently delete your account and remove your data from our servers.
---
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
---
<AlertDialog>
<AlertDialogTrigger variant="outline">Show Dialog</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete your account
and remove your data from our servers.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction>Continue</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>Installation
npx shadcn@latest add @fulldev/alert-dialog
Usage
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
<AlertDialog>
<AlertDialogTrigger variant="outline">Show Dialog</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete your account
and remove your data from our servers.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction>Continue</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
Composition
Use the following composition to build an AlertDialog:
AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
├── AlertDialogHeader
│ ├── AlertDialogMedia
│ ├── AlertDialogTitle
│ └── AlertDialogDescription
└── AlertDialogFooter
├── AlertDialogCancel
└── AlertDialogAction
Notes
- Use
AlertDialogfor irreversible or high-risk actions, not routine inline confirmations. - Keep
AlertDialogTitleandAlertDialogDescriptioninsideAlertDialogContentso screen readers announce the dialog context clearly. - Use
AlertDialogCancelfor dismissive actions. It closes the dialog automatically. AlertDialogActionis an action hook and does not close the dialog. Run the confirmation first, then close the dialog with the documentedalert-dialog:setevent when the action succeeds.- Use
size="sm"onAlertDialogContentfor compact confirmations andAlertDialogMediawhen the dialog needs an icon or visual cue.
<AlertDialog id="account-deletion-dialog">
<AlertDialogTrigger>Delete account</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogTitle>Delete this account?</AlertDialogTitle>
<AlertDialogDescription>This cannot be undone.</AlertDialogDescription>
<AlertDialogAction id="confirm-account-deletion">
Delete account
</AlertDialogAction>
</AlertDialogContent>
</AlertDialog>
<script>
const dialog = document.getElementById("account-deletion-dialog")
const action = document.getElementById("confirm-account-deletion")
action?.addEventListener("click", () => {
// Run the confirmed action here, then close after it succeeds.
dialog?.dispatchEvent(
new CustomEvent("alert-dialog:set", {
detail: { open: false },
})
)
})
</script>
API Reference
See the GitHub source code for more information on props. See the data-slot docs for more information on interactivity.