Alert Dialog
A modal dialog that interrupts the user with important content and expects a response.
Installation
pnpm dlx cubix@latest add alert-dialog --base ariaUsage
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/cubix/alert-dialog"<AlertDialog>
<AlertDialogTrigger render={<Button variant="outline" />}>
Show Dialog
</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>Composition
Use the following composition to build an Alert Dialog:
AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
├── AlertDialogHeader
│ ├── AlertDialogMedia
│ ├── AlertDialogTitle
│ └── AlertDialogDescription
└── AlertDialogFooter
├── AlertDialogCancel
└── AlertDialogActionExamples
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 an icon or image above the title.
Small with Media
Combine size="sm" with AlertDialogMedia for a compact dialog with an icon.
Destructive
Use variant="destructive" on the action when the confirm step cannot be undone.
RTL
Set dir="rtl" and lang="fa" on the trigger wrapper and on AlertDialogContent so layout, actions, and IRANSans XV follow Persian. The panel is portaled, so it needs those attributes too.
API Reference
Note: Alert dialogs trap focus and require an explicit choice. Prefer this over a regular Dialog when the user must confirm or cancel.
AlertDialog
The container that wraps the trigger and content and manages open state.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode | - | The trigger and content elements. State is managed internally (uncontrolled). |
AlertDialogTrigger
The element that opens the dialog. Use render to merge onto a Button.
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.ReactElement | - | Render the trigger as another element (e.g. a Button). |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogContent
The modal panel rendered with a backdrop.
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "default" | "sm" | "default" | Width of the alert dialog panel. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogHeader / AlertDialogMedia / AlertDialogFooter
Layout regions of the dialog content.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogTitle / AlertDialogDescription
The title and supporting text of the dialog.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogAction
The confirm button. Use a destructive variant for irreversible actions.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | "default" | Visual style of the confirm button. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogCancel
The dismiss button. Closes the dialog without confirming.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | "outline" | Visual style of the cancel button. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |