Pickers and overlays
Alert Dialog
A modal layer for a serious decision that needs attention.
When to use it: Use it before destructive or hard-to-undo actions.
Example
import { AlertDialog, AlertDialogContent, Button, DialogTrigger } from "@comp0/react";
export function Example() {
return (
<AlertDialog>
<DialogTrigger className="rounded border border-red-950/10 px-3 py-2.5 text-base text-red-700 sm:py-2 sm:text-sm dark:border-red-200/10 dark:text-red-300">
Delete draft
</DialogTrigger>
<AlertDialogContent
aria-label="Delete draft"
className="m-auto w-[min(24rem,calc(100vw-2rem))] rounded-[min(1vw,12px)] bg-white p-4 text-zinc-900 shadow-2xl ring-1 ring-red-950/10 backdrop:bg-zinc-950/40 dark:bg-zinc-900 dark:text-zinc-50 dark:shadow-none dark:ring-red-200/10"
>
<div className="flex flex-col gap-2">
<p className="text-base font-medium sm:text-sm">Delete this draft?</p>
<p className="text-base text-zinc-600 sm:text-sm dark:text-zinc-400">
This action cannot be undone.
</p>
<form method="dialog" className="flex gap-2 pt-2">
<Button
className="rounded border border-zinc-950/10 px-3 py-2.5 text-base text-zinc-800 sm:py-2 sm:text-sm dark:border-white/10 dark:text-zinc-100"
type="submit"
>
Cancel
</Button>
<Button
className="rounded bg-red-600 px-3 py-2.5 text-base text-white sm:py-2 sm:text-sm"
type="submit"
>
Delete
</Button>
</form>
</div>
</AlertDialogContent>
</AlertDialog>
);
}Anatomy
Dashed frames are invisible state providers; shaded shapes own real DOM. Numbered pins match the list below.
A wireframe sketch of the assembled component. Each numbered marker matches a part in the list that follows.
AlertDialog
Modal open-state provider for an urgent decision. Does not add a DOM element.
DialogTrigger
Button that opens the alert. Owns a DOM element.
AlertDialogContent
Modal alert dialog content. Owns a DOM element.
Step by step
- 1
Add the main part
Start AlertDialog with the button that begins the decision.
- 2
Add the supporting parts
Put plain consequences and clear choices in AlertDialogContent.
- 3
Make the behavior clear
Make the safe or cancel choice easy to find.
Exampletsx <AlertDialog><DialogTrigger>Delete</DialogTrigger><AlertDialogContent aria-label="Delete item">This cannot be undone.</AlertDialogContent></AlertDialog>
Keyboard
- Esc
- Closes when dismissal is allowed.
- ⇥
- Cycles inside the modal.
Forms and accessibility
No native form behavior; put a confirmation form inside when needed.
Accessibility checklist
- Name the consequence, not just the button.
- Put the safer choice where it is easy to find.
- Do not use an alert dialog for ordinary, reversible actions.
API reference
import { AlertDialog, AlertDialogContent, DialogTrigger } from "@comp0/react";AlertDialog
Context onlyModal open-state provider for an urgent decision.
| Prop | Type | Description |
|---|---|---|
open / defaultOpen | boolean | Controlled or initial open state. |
onToggle | (open: boolean) => void | Receives the next open state. |
DialogTrigger
DOM elementButton that opens the alert.
| Prop | Type | Description |
|---|---|---|
as | ElementType | Fragment | Fragment merges the trigger onto your own element child. |
AlertDialogContent
DOM elementModal alert dialog content.
| Prop | Type | Description |
|---|---|---|
aria-label | string | Accessible name for the decision. |
portal | boolean | Renders into document.body; on by default. |
closedby | "any" | "closerequest" | "none" | Native dismissal policy; none blocks Escape when the decision must be explicit. |
Style hooks
Attributes that appear while a state is true. Target them with Tailwind data variants such as data-open:bg-zinc-100, or with any CSS selector.
[data-open]on DialogTrigger, AlertDialogContent
- The alert is open.
:openon AlertDialogContent
- Native pseudo-class equivalent.