ToroUI

Alert Dialog

A modal dialog that interrupts the user with important content and expects a response.


A composable alert dialog built on Base UI's AlertDialog primitive. Use it for destructive confirmations or important decisions that require the user to acknowledge before continuing.

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

export default function AlertDialogDemo() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="outline" />}>
        Delete account
      </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 variant="destructive">Delete</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}

Anatomy

import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogHeader,
  AlertDialogFooter,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogMedia,
  AlertDialogOverlay,
  AlertDialogPortal,
} from "@/components/ui/alert-dialog"
<AlertDialog>
  <AlertDialogTrigger>
    <Button>Open</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you sure?</AlertDialogTitle>
      <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Continue</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Examples

Basic confirmation

<AlertDialog>
  <AlertDialogTrigger>
    <Button variant="destructive">Delete account</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Delete account?</AlertDialogTitle>
      <AlertDialogDescription>
        This will permanently delete your account and all associated data.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction variant="destructive">Delete</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Small size

Use size="sm" on AlertDialogContent for a compact, centered layout with a two-column footer.

<AlertDialog>
  <AlertDialogTrigger>
    <Button>Confirm</Button>
  </AlertDialogTrigger>
  <AlertDialogContent size="sm">
    <AlertDialogHeader>
      <AlertDialogTitle>Confirm action</AlertDialogTitle>
      <AlertDialogDescription>Are you sure you want to proceed?</AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>No</AlertDialogCancel>
      <AlertDialogAction>Yes</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

With media

Use AlertDialogMedia inside the header to display an icon or illustration alongside the title and description.

<AlertDialog>
  <AlertDialogTrigger>
    <Button>Open</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogMedia>
        <TrashIcon />
      </AlertDialogMedia>
      <AlertDialogTitle>Delete item</AlertDialogTitle>
      <AlertDialogDescription>
        This item will be permanently removed.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction variant="destructive">Delete</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

API Reference

AlertDialog

The root component. Manages open/closed state.

PropTypeDefaultDescription
openbooleanControlled open state.
onOpenChange(open: boolean) => voidCallback when the open state changes.
childrenReactNode

AlertDialogTrigger

The element that opens the dialog.

PropTypeDefault
classNamestring
childrenReactNode

AlertDialogContent

The dialog popup panel. Automatically renders inside a portal with a backdrop overlay.

PropTypeDefaultDescription
size"default" | "sm""default"Controls the max-width and layout. "sm" produces a compact centered dialog.
classNamestring
childrenReactNode

AlertDialogOverlay

The backdrop behind the dialog. Renders a blurred, semi-transparent overlay.

PropTypeDefault
classNamestring

AlertDialogPortal

Renders children into a React portal.

PropTypeDefault
childrenReactNode

AlertDialogHeader

Layout container for the title, description, and optional media.

PropTypeDefault
classNamestring
childrenReactNode

AlertDialogFooter

Layout container for the action and cancel buttons.

PropTypeDefault
classNamestring
childrenReactNode

AlertDialogMedia

An icon or illustration area inside the header. Renders as a 64px square with a muted background.

PropTypeDefault
classNamestring
childrenReactNode

AlertDialogTitle

The dialog title.

PropTypeDefault
classNamestring
childrenReactNode

AlertDialogDescription

The dialog description text.

PropTypeDefault
classNamestring
childrenReactNode

AlertDialogAction

A styled Button for the primary action (e.g. "Delete", "Continue"). Accepts all Button props.

PropTypeDefault
variantButtonVariant"default"
sizeButtonSize"default"
classNamestring
childrenReactNode

AlertDialogCancel

A close button for cancelling the dialog. Renders as an outline Button by default.

PropTypeDefaultDescription
variantButtonVariant"outline"The button variant.
sizeButtonSize"default"The button size.
classNamestring
childrenReactNode