Skip to content
Haze UI

Dialog

Native modal with a title, description, body, and footer actions.

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

When to use

  • A short task that needs the user's full attention, such as inviting a teammate
  • Collecting a short decision or additional context before continuing
  • A form with one to four fields that does not deserve its own page

When not to use

  • Long or multi-step flows need their own page.
  • Status messages that need no decision; use alert
  • A destructive confirmation needs an explicit choice. Use alert-dialog.

Installation

Add the Haze registry to components.json once, then install Dialog with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/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 on the page. Buttons target it with commandfor="<id>".
title*string–Heading; also the dialog's accessible name.
descriptionstring–One or two sentences under the title.
triggerbooleantrueSet to false when the opening button lives elsewhere.
triggerLabelstring"Open dialog"Trigger text when the trigger slot is not used.
triggerVariant"primary" | "secondary" | "outline" | "ghost""outline"Trigger button style.
size"sm" | "md" | "lg""md"Maximum width: 24, 28 or 42 rem.
closeLabelstring"Close"Accessible name of the close button; translate it.
role"dialog" | "alertdialog""dialog"Alert dialogs omit the close icon and require a closing action or Escape.
headingLevel2 | 3 | 4 | 5 | 62Heading level for the dialog title.
classstring–Extra classes on the dialog.
default slotslot–Body content.
footer slotslot–Action buttons. Close with command="close" commandfor="<id>" or a form with method="dialog".
trigger slotslot–Custom trigger content.

Keyboard interactions

EnterSpace
Open the dialog from the trigger
TabShiftTab
Move between controls; focus stays inside the dialog
Escape
Close the dialog and return focus to the trigger

Accessibility

  • showModal() semantics: the page behind is inert, focus moves into the dialog and returns to the trigger on close.
  • Opening uses the command and commandfor attributes (Chrome 135, Firefox 144, Safari 26.2). The small script covers older browsers; without both, the trigger does nothing.
  • The dialog fades and scales in over 200 ms and out again, and its backdrop fades with it; reduced-motion users get no animation.
  • The title is linked with aria-labelledby and the description with aria-describedby.
  • Put the least destructive action first in the DOM so it receives initial focus.

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 "Dialog" with `npx shadcn@latest add @haze/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 Dialog from "@/components/haze/ui/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/dialog.md

  • Customize with real content

    Adapt the Haze dialog ui for our product. Replace the demo values of these props with our real content: id, title, description, trigger, triggerLabel, triggerVariant, size, closeLabel, role, headingLevel, class, default slot, footer slot, trigger slot. Keep the layout, the heading level rules and these accessibility details: showModal() semantics: the page behind is inert, focus moves into the dialog and returns to the trigger on close. Opening uses the command and commandfor attributes (Chrome 135, Firefox 144, Safari 26.2). The small script covers older browsers; without both, the trigger does nothing. The dialog fades and scales in over 200 ms and out again, and its backdrop fades with it; reduced-motion users get no animation. The title is linked with aria-labelledby and the description with aria-describedby. Put the least destructive action first in the DOM so it receives initial focus. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using dialog, check it fits: use it when a short task that needs the user's full attention, such as inviting a teammate; collecting a short decision or additional context before continuing; a form with one to four fields that does not deserve its own page. Avoid it when long or multi-step flows need their own page.; status messages that need no decision; use alert; a destructive confirmation needs an explicit choice. use alert-dialog.. Alternatives: @haze/popover, @haze/alert, @haze/alert-dialog.

Dependencies

  • npm: @lucide/astro
  • @haze/button
  • @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