Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Alert Dialog for React

A modal for critical confirmations and destructive actions.

Installation

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

Anatomy

AlertDialogTrigger
AlertDialogOverlay
AlertDialogContent
└── AlertDialogPositioner
AlertDialogTitle
AlertDialogDescription
AlertDialogAction

Usage

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button variant="outline">Show Dialog</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone. This will permanently delete your
        account from our servers.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Continue</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Accessibility

KeyDescription
Enter
Activate the focused control.
Space
Activate the focused control.

Demos

Basic

A basic alert dialog with a title, description, and cancel and continue buttons.

Small

Use the size="sm" prop to make the alert dialog smaller.

Media

Use AlertDialogMedia to add a media element such as an icon or image.

Small Media

Use size="sm" with AlertDialogMedia for a compact dialog with an icon.

Destructive

Use AlertDialogAction with variant="destructive" for a destructive action.

Rtl

Right-to-left alert dialog. See the RTL configuration guide for document direction.

API Reference

AlertDialog

PropType
childrenReact.ReactNode
AttributeType

AlertDialogTrigger

PropType
childrenReact.ReactNode
className?string
AttributeType

AlertDialogOverlay

PropType
childrenReact.ReactNode
AttributeType

AlertDialogContent

PropType
childrenReact.ReactNode
className?string

AlertDialogHeader

PropType
childrenReact.ReactNode
AttributeType

AlertDialogFooter

PropType
childrenReact.ReactNode
AttributeType

AlertDialogMedia

PropType
childrenReact.ReactNode
AttributeType

AlertDialogTitle

PropType
childrenReact.ReactNode

AlertDialogDescription

PropType
childrenReact.ReactNode

AlertDialogAction

PropType
childrenReact.ReactNode
AttributeType

AlertDialogCancel

PropType
childrenReact.ReactNode
AttributeType