Alert dialog
A native confirmation dialog that starts focus on Cancel and ignores outside clicks.
pnpm dlx shadcn@latest add @haze/alert-dialog---
import { cn } from "../../../lib/haze/utils";
import Button from "./button.astro";
import Dialog from "./dialog.astro";
interface Props {
id: string;
title?: string;
description?: string;
trigger?: boolean;
triggerLabel?: string;
cancelLabel?: string;
confirmLabel?: string;
confirmForm?: string;
destructive?: boolean;
headingLevel?: 2 | 3 | 4 | 5 | 6;
class?: string;
}
const {
id, title = "Discard this draft?", description = "Your unsaved edits will be lost.",
trigger = true, triggerLabel = "Discard draft", cancelLabel = "Keep editing", confirmLabel = "Discard draft",
confirmForm, destructive = true, headingLevel = 2, class: className,
} = Astro.props;
---
<Dialog id={id} title={title} description={description} trigger={trigger} triggerLabel={triggerLabel}
role="alertdialog" size="sm" headingLevel={headingLevel} class={cn(className)}>
<slot />
<form method="dialog" slot="footer" class="grid w-full gap-2 sm:flex sm:justify-end">
<Button type="submit" value="cancel" autofocus variant="outline" class="whitespace-normal">{cancelLabel}</Button>
<Button type="submit" form={confirmForm} value="confirm" variant={destructive ? "destructive" : "primary"} class="whitespace-normal">{confirmLabel}</Button>
</form>
</Dialog>When to use
- People must acknowledge the consequence of discarding, revoking, or deleting something
- A short irreversible action needs distinct cancel and confirm labels
When not to use
- The modal collects fields or longer content. Use dialog.
- A routine notification can be read without interrupting the user. Use alert.
Installation
Add the Haze registry to components.json once, then install Alert dialog with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/alert-dialognpx shadcn@latest add @haze/alert-dialogyarn dlx shadcn@latest add @haze/alert-dialogbunx --bun shadcn@latest add @haze/alert-dialogFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique dialog ID. An external trigger can target it with commandfor. |
| title | string | "Discard this draft?" | Question or brief confirmation title. |
| description | string | "Your unsaved edits will be lost." | Consequence of accepting the action. |
| trigger | boolean | true | Renders the default opener. |
| triggerLabel | string | "Discard draft" | Text on the opener. |
| cancelLabel | string | "Keep editing" | Label of the cancel action. |
| confirmLabel | string | "Discard draft" | Label of the confirm action. |
| confirmForm | string | – | ID of a form outside the dialog to submit. When omitted, confirmation closes with returnValue confirm. |
| destructive | boolean | true | Uses destructive styling for confirmation. |
| headingLevel | 2 | 3 | 4 | 5 | 6 | 2 | Heading level for the title. |
| default slot | slot | – | Optional content below the description. |
| class | string | – | Additional classes on the dialog. |
Keyboard interactions
- Enter or Space
- Open the dialog or activate the focused action.
- Escape
- Cancel and restore focus to the trigger.
Accessibility
- Initial focus is on Cancel. The native modal manages focus containment and restoration.
- Handle the close event and look for returnValue equal to confirm before accepting the result.
- Place the dialog outside its optional submission form and explain the specific consequence in the description.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Alert dialog" with `npx shadcn@latest add @haze/alert-dialog`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AlertDialog from "@/components/haze/ui/alert-dialog.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/alert-dialog.md
Customize with real content
Adapt the Haze alert-dialog ui for our product. Replace the demo values of these props with our real content: id, title, description, trigger, triggerLabel, cancelLabel, confirmLabel, confirmForm, destructive, headingLevel, default slot, class. Keep the layout, the heading level rules and these accessibility details: Initial focus is on Cancel. The native modal manages focus containment and restoration. Handle the close event and look for returnValue equal to confirm before accepting the result. Place the dialog outside its optional submission form and explain the specific consequence in the description. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using alert-dialog, check it fits: use it when people must acknowledge the consequence of discarding, revoking, or deleting something; a short irreversible action needs distinct cancel and confirm labels. Avoid it when the modal collects fields or longer content. use dialog.; a routine notification can be read without interrupting the user. use alert.. Alternatives: @haze/dialog, @haze/alert.
Dependencies
- @haze/button
- @haze/dialog
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.