Component guideEditable source

Alert Dialog

A modal confirmation for an action that needs an explicit decision.

Original component docs
On this page4 sectionsBack to top

Use Alert Dialog before a consequential operation. Use Dialog for ordinary editing. Explain the actual consequence instead of asking only “Are you sure?”.

Live preview
Loading preview...

#Installation

Complete the base setup first. The CLI includes dependencies. For manual installation:

npx shadcn@latest add https://neobrutal-ui.andongmin.com/r/alert-dialog.json

#Usage

import { Button } from "@/components/ui/button";
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog";

export default function ConfirmArchive({ onArchive }: { onArchive: () => void }) {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="outline" />}>Archive project</AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Archive this project?</AlertDialogTitle>
          <AlertDialogDescription>
            The project will leave the active list. You can restore it later.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Keep project</AlertDialogCancel>
          <AlertDialogAction onClick={onArchive}>Archive project</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}

#API reference

Prop / partPurposeDefault
AlertDialog.open / onOpenChangeControlled modal stateUncontrolled
AlertDialog.defaultOpenInitial visibilityfalse
AlertDialogTrigger.renderCompose a trigger buttonPrimitive button
AlertDialogTitle / AlertDialogDescriptionAccessible name and consequence—
AlertDialogCancelCancel and restore focusStyled close button
AlertDialogActionConfirm and closeStyled close button
AlertDialogContent.sizeDialog width: default or smdefault
AlertDialogAction.size / variantConfirmation button size and appearancedefault / default
AlertDialogCancel.size / variantCancellation button size and appearancedefault / neutral

#Accessibility

Keep a meaningful title and description. The modal traps keyboard focus and normally returns focus to its trigger. Cancel must be easy to identify. Closing the dialog does not prove that a server operation succeeded: for asynchronous work, control open, show failure inside the dialog, and close only after success.