Skip to content
Haze UI

Alert dialog

A native confirmation dialog that starts focus on Cancel and ignores outside clicks.

pnpm dlx shadcn@latest add @haze/alert-dialog
Open preview in a new tab
Livesmall script

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-dialog
First 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

PropTypeDefaultDescription
id*string–Unique dialog ID. An external trigger can target it with commandfor.
titlestring"Discard this draft?"Question or brief confirmation title.
descriptionstring"Your unsaved edits will be lost."Consequence of accepting the action.
triggerbooleantrueRenders the default opener.
triggerLabelstring"Discard draft"Text on the opener.
cancelLabelstring"Keep editing"Label of the cancel action.
confirmLabelstring"Discard draft"Label of the confirm action.
confirmFormstring–ID of a form outside the dialog to submit. When omitted, confirmation closes with returnValue confirm.
destructivebooleantrueUses destructive styling for confirmation.
headingLevel2 | 3 | 4 | 5 | 62Heading level for the title.
default slotslot–Optional content below the description.
classstring–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.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog