Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

Shadcn Alert Dialog for React and Tailwind

A modal for critical confirmations and destructive actions.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/alert-dialog.json

Anatomy

AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
    ├── AlertDialogHeader
    │   ├── AlertDialogTitle
    │   └── AlertDialogDescription
    ├── AlertDialogBody
    ├── AlertDialogFooter
    │   ├── AlertDialogCancel
    │   └── AlertDialogAction
    └── AlertDialogClose

Usage

import { 
  AlertDialog, 
  AlertDialogTrigger, 
  AlertDialogContent, 
  AlertDialogHeader,
  AlertDialogTitle, 
  AlertDialogDescription, 
  AlertDialogBody,
  AlertDialogFooter,
  AlertDialogAction,
  AlertDialogCancel,
} from "@/components/ui/alert-dialog";
<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button variant="outline">Open</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader
      title="Allow accessory to connect?"
      description="Do you want to allow the USB accessory to connect to this device?"
    />
    <AlertDialogFooter>
      <AlertDialogCancel>Don't allow</AlertDialogCancel>
      <AlertDialogClose asChild>
        <AlertDialogAction>Allow</AlertDialogAction>
      </AlertDialogClose>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Alert Dialog is Dialog with role="alertdialog". Differences:

  • Focus moves to a safe action (typically Cancel) when possible
  • Does not close on outside click (closeOnInteractOutside={false})
  • Must be dismissed with a button or Escape
  • The corner close button is hidden (showCloseButton={false})

Title & Description

AlertDialogHeader supports two usage patterns:

Using props

Pass title and description props directly to AlertDialogHeader.

<AlertDialogHeader 
  title="Allow accessory to connect?" 
  description="Do you want to allow the USB accessory to connect to this device?"
>
  <AlertDialogAction />
</AlertDialogHeader>

This approach does not require AlertDialogTitle or AlertDialogDescription components.

Using components

Use AlertDialogTitle and AlertDialogDescription as children for more control.

<AlertDialogHeader>
  <AlertDialogTitle>Allow accessory to connect?</AlertDialogTitle>
  <AlertDialogDescription>
    Do you want to allow the USB accessory to connect to this device?
  </AlertDialogDescription>
  <AlertDialogAction />
</AlertDialogHeader>

Examples

Destructive

API Reference

AlertDialog accepts every Dialog root prop. Defaults that differ from Dialog:

PropAlert Dialog defaultDialog default
role"alertdialog""dialog"
closeOnInteractOutsidefalsetrue

asChild merges props onto a single child element.

AlertDialog

Root. Same props as Dialog.

AttributeDescription
data-slotalert-dialog-root
rolealertdialog

AlertDialogTrigger

Same as DialogTrigger.

AttributeDescription
data-slotalert-dialog-trigger

AlertDialogContent

Same as DialogContent, with showCloseButton={false} by default.

PropTypeDefaultDescription
size"sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "fullscreen""md"Max width of the panel.
showCloseButtonbooleanfalseShow the top-end close button.
bottomStickOnMobilebooleantrueStick to the bottom of the viewport below sm.
positionerClassNamestring-Class names on the positioner.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the panel.
AttributeDescription
data-slotalert-dialog-content

AlertDialogHeader

Same as DialogHeader.

PropTypeDefaultDescription
titlestring-Renders AlertDialogTitle.
descriptionstring-Renders AlertDialogDescription.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the header.
AttributeDescription
data-slotalert-dialog-header

AlertDialogTitle

Same as DialogTitle. Required for accessibility.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the title.
AttributeDescription
data-slotalert-dialog-title

AlertDialogDescription

Same as DialogDescription.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the description.
AttributeDescription
data-slotalert-dialog-description

AlertDialogBody

Same as DialogBody.

PropTypeDefaultDescription
scrollFadebooleanfalseFade the edges of the scroll area.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the body.
AttributeDescription
data-slotalert-dialog-body

AlertDialogFooter

Same as DialogFooter.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the footer.
AttributeDescription
data-slotalert-dialog-footer

AlertDialogClose

Same as DialogClose.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the close control.
AttributeDescription
data-slotalert-dialog-close

AlertDialogCancel

Cancel action. Renders AlertDialogClose around an outline Button. Put this first so it is the safer focused control.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the button.
childrenReactNode-Button label.
AttributeDescription
data-slotalert-dialog-cancel

AlertDialogAction

Primary action. Renders a Button. Wrap it in AlertDialogClose when the action should also dismiss the dialog.

PropTypeDefaultDescription
variant"default" | "destructive""default"Button variant. Use "destructive" for delete/remove.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the button.
childrenReactNode-Button label.

Accessibility

Complies with the Alert Dialog WAI-ARIA pattern. Always include a title. Prefer AlertDialogCancel as the first footer action.

Keyboard support

KeyDescription
EnterWhen focus is on the trigger, opens the dialog.
TabMove to the next focusable element. Focus is trapped.
Shift + TabMove to the previous focusable element. Focus is trapped.
EscapeClose the dialog and return focus to the trigger.