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.jsonnpx shadcn@latest add https://kit.dev/r/aria/alert-dialog.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/alert-dialog.jsonyarn shadcn@latest add https://kit.dev/r/aria/alert-dialog.jsonThis component depends on Button. Install it first if you haven't already.
Install the following dependencies:
bun add react-aria-components tailwind-variantsnpm install react-aria-components tailwind-variantspnpm add react-aria-components tailwind-variantsyarn add react-aria-components tailwind-variantsCopy and paste the following code into your project.
"use client";
import type React from "react";
import {
Dialog as AlertDialogPrimitive,
DialogTrigger as AlertDialogTriggerPrimitive,
type DialogTriggerProps as AlertDialogTriggerPrimitiveProps,
Heading,
ModalOverlay as ModalOverlayPrimitive,
type ModalOverlayProps as ModalOverlayPrimitiveProps,
Modal as ModalPrimitive,
} from "react-aria-components";
import { cn } from "@/lib/utils";
import { Button, type ButtonProps } from "@/registry/aria/components/button";
export const AlertDialogTrigger = (props: AlertDialogTriggerPrimitiveProps) => (
<AlertDialogTriggerPrimitive data-slot="alert-dialog-trigger" {...props} />
);Update the import paths to match your project setup.
Anatomy
AlertDialogTrigger
AlertDialogOverlay
AlertDialogContent
└── AlertDialogPositioner
AlertDialogTitle
AlertDialogDescription
AlertDialogActionUsage
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
| Key | Description |
|---|---|
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.ReactNodeAttributeType
AlertDialogTrigger
PropType
childrenReact.ReactNodeclassName?stringAttributeType
AlertDialogOverlay
PropType
childrenReact.ReactNodeAttributeType
AlertDialogContent
PropType
childrenReact.ReactNodeclassName?stringAlertDialogHeader
PropType
childrenReact.ReactNodeAttributeType
AlertDialogFooter
PropType
childrenReact.ReactNodeAttributeType
AlertDialogMedia
PropType
childrenReact.ReactNodeAttributeType
AlertDialogTitle
PropType
childrenReact.ReactNodeAlertDialogDescription
PropType
childrenReact.ReactNodeAlertDialogAction
PropType
childrenReact.ReactNodeAttributeType
AlertDialogCancel
PropType
childrenReact.ReactNodeAttributeType