Alert Dialog

A modal dialog for important confirmations that expects a response.

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 AlertDialog for irreversible or high-risk actions, not routine inline confirmations.
  • Keep AlertDialogTitle and AlertDialogDescription inside AlertDialogContent so screen readers announce the dialog context clearly.
  • Use AlertDialogCancel for dismissive actions. It closes the dialog automatically.
  • AlertDialogAction is an action hook and does not close the dialog. Run the confirmation first, then close the dialog with the documented alert-dialog:set event when the action succeeds.
  • Use size="sm" on AlertDialogContent for compact confirmations and AlertDialogMedia when 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.