Alert Dialog

Use AlertDialog when an action needs explicit confirmation, particularly when its result is hard to undo.

Preview

Confirm draft deletion

Require an explicit delete action and report its local result after the dialog closes.

Loading preview.

Installation

New to this Registry? Complete the base setup before continuing.

npx shadcn@latest add @neumorphism-ui/alert-dialog

Install the shared base once, then add components and their dependencies with the CLI.

Confirm draft deletion

npx shadcn@latest add @neumorphism-ui/button @neumorphism-ui/alert-dialog
Registry JSON

Usage

Explain the consequence with a title and description. Provide separate cancel and action controls, and attach the operation to the action rather than opening the dialog.

"use client";

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

export default function Example() {
  const [deleted, setDeleted] = useState(false);
  return (
    <div>
      <AlertDialog>
        <AlertDialogTrigger render={<Button variant="destructive" />}>Delete draft</AlertDialogTrigger>
        <AlertDialogContent>
          <AlertDialogTitle>Delete this draft?</AlertDialogTitle>
          <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription>
          <AlertDialogFooter>
            <AlertDialogCancel>Cancel</AlertDialogCancel>
            <AlertDialogAction onClick={() => setDeleted(true)}>Delete</AlertDialogAction>
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
      <p role="status">{deleted ? "Draft deleted." : "Draft available."}</p>
    </div>
  );
}

API Reference

An explicit confirmation for an irreversible action. Place Cancel first. For asynchronous work, close a controlled dialog only after success.

ComponentPropTypeDefaultDescription
AlertDialogopen / defaultOpenboolean—Set controlled or initial state.
AlertDialogContentinitialFocusboolean | React.RefObject | function—Choose the focus target when opening.
AlertDialogActiononClickReact.MouseEventHandler—Handle a synchronous confirmation; use controlled state for asynchronous work.

Accessibility

  • 01

    Place Cancel first. For asynchronous work, close a controlled dialog only after success.

  • 02

    Preserve labels and visible focus when customizing render or className.