AlertDialog
A modal dialog that interrupts the user with important content and expects a response. Unlike Dialog, AlertDialog does NOT dismiss on backdrop click or Escape — the user must explicitly choose an action.
Use cases
- Destructive confirmations — "Delete this item? This cannot be undone."
- Irreversible actions — submitting a form, publishing content, sending a message.
- Critical warnings — session expiry, unsaved changes, data loss.
When NOT to use
- For non-blocking information — use Dialog or Toast.
- For inline confirmations — use an inline confirmation pattern.
- For simple notifications — use Alert.
Import
import {
AlertDialog,
AlertDialogContent,
AlertDialogHeader,
AlertDialogBody,
AlertDialogFooter,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogAction,
AlertDialogCancel,
} from '@mihcm/ui/AlertDialog';Basic usage
const [open, setOpen] = useState(false);
<AlertDialog open={open} onOpenChange={setOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete your account.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel onClick={() => setOpen(false)}>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleDelete}>Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>Composition
AlertDialogCancelmaps to the safe exit.AlertDialogActionmaps to the confirming action.- For destructive actions, use
variant="destructive"on the Action button. - Unlike Dialog, outside click and
Escapedo NOT dismiss — the user must pick Cancel or the action. AlertDialogTitleandAlertDialogDescriptionare required for screen reader announcements.AlertDialogContentapplies an automaticgap-y-4row gap between its direct children (Header / Body / Footer). You never need to addmt-*/mb-*between sections.- Use
AlertDialogBodywhenever the alert needs custom middle content — confirmation input, checkbox, extra explanation. It provides matchingpx-6horizontal padding so the body lines up with Header and Footer; vertical spacing comes from the parent's gap. See the Confirmation input example.