A question that has to be answered before anything else: Cancel, or confirm what can't be undone.
$ pnpm dlx shadcn@latest add https://dashral.com/r/alert-dialog.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/alert-dialog.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/alert-dialogUsage
import { Button } from "@/components/dashral/button"
import { AlertDialog } from "@/components/dashral/alert-dialog"
<AlertDialog
trigger={<Button color="destructive">Delete project</Button>}
title="Delete this project?"
description="Its 12 dashboards go with it. This can't be undone."
color="destructive"
confirmLabel="Delete"
loadingText="Deleting…"
onConfirm={() => api.projects.delete(project.id)}
/>Examples
API reference
AlertDialog
Also takes every prop of Radix Alert Dialog(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
trigger | ReactElementWhat opens it, e.g. a Delete button. Leave it out to open it with open / onOpenChange. | — |
title | ReactNodeRequired: the question, which names the dialog. | — |
description | ReactNodeWhat happens if they go ahead. | — |
children | ReactNodeMore between the text and the buttons, e.g. a field to type a name. | — |
icon | ReactNodeIn a tinted circle beside the text. | — |
color | "primary" | "destructive"The confirm button's (and the icon's) color; destructive for deleting. | "primary" |
confirmLabel / cancelLabel | ReactNodeThe buttons' labels (translated by default). | "Continue" / "Cancel" |
onConfirm | () => void | Promise<unknown>Runs on confirm. A promise keeps the dialog open with the button showing it's working; it closes when the promise resolves, and stays if it rejects. | — |
loadingText | ReactNodeBeside the spinner while onConfirm's promise runs. | — |
confirmDisabled | booleanKeeps confirm off, e.g. until a name is typed. | false |
open / defaultOpen / onOpenChange | Controlled or initial state. | — |
classNames | { title, description, footer }Classes for each part. | — |
className | stringThe panel's classes. | — |
Keyboard
| Keys | Action |
|---|---|
| Tab | Move between the buttons (and anything in the body) |
| EnterorSpace | Press the focused button: Cancel has the focus when it opens |
| Escape | Cancel |
Accessibility
- role="alertdialog" with aria-modal, labelled by its title and described by its description.
- It can't be dismissed by clicking outside, and Cancel takes the focus when it opens, so Enter never confirms by accident.
- While onConfirm runs, the confirm button is aria-busy and Escape and Cancel wait.
Motion
- The panel springs in from 95% with a soft blur clearing; the backdrop fades in. Closing is quicker.