Skip to content
Haze UI

Form

A form wrapper that replaces native validation bubbles with an error summary, linked to each invalid field and its inline message.

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

When to use

  • A signup, invite or settings form with several required fields
  • You want every error listed at the top with a link to the field, plus a message under it
  • Native browser validation should still work if the script does not run

When not to use

  • A single field with one error line. Use field.
  • You only need to group related controls under a legend. Use fieldset.
  • A one-input search or newsletter box. Use input-group.

Installation

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

pnpm dlx shadcn@latest add @haze/form
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–Form id. The summary id derives from it.
actionstring–Where the form posts.
method"get" | "post" | "dialog"–Form method.
novalidatebooleanfalseTurns native bubbles off in the markup. The script does it anyway.
summaryTitlestring"Fix {count} problems to continue"Summary title for two or more problems; {count} becomes the number.
summaryTitleOnestring"Fix 1 problem to continue"Summary title for exactly one problem.
submitLabelstring–Adds a built-in submit button with this label.
fallbackLabelstring"This field"Name used in the summary when a control has no label.
classstring–Extra classes on the form.
default slot*slot–Fields: field, checkbox and similar controls.
actionsslot–Buttons placed after the built-in submit button.

Keyboard interactions

Tab
After a failed submit, move from the summary through its links to the fields.
Enter on a summary link
Move focus to that field.

Accessibility

  • On a failed submit the summary panel (role alert) takes focus and lists each problem as a link to its field.
  • Every invalid control gets aria-invalid and an inline message linked through aria-describedby; the message has an icon and text, never color alone.
  • Add data-error="…" to a control to replace the browser's wording in both the summary and the inline message.
  • Fields are rechecked on blur after the first attempt, and on input while invalid. The summary updates only when the set of invalid fields changes, so a screen reader is not interrupted on every keystroke.
  • Without script the browser's own validation bubbles still block an incomplete submit.

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

  • Customize with real content

    Adapt the Haze form ui for our product. Replace the demo values of these props with our real content: id, action, method, novalidate, summaryTitle, summaryTitleOne, submitLabel, fallbackLabel, class, default slot, actions. Keep the layout, the heading level rules and these accessibility details: On a failed submit the summary panel (role alert) takes focus and lists each problem as a link to its field. Every invalid control gets aria-invalid and an inline message linked through aria-describedby; the message has an icon and text, never color alone. Add data-error="…" to a control to replace the browser's wording in both the summary and the inline message. Fields are rechecked on blur after the first attempt, and on input while invalid. The summary updates only when the set of invalid fields changes, so a screen reader is not interrupted on every keystroke. Without script the browser's own validation bubbles still block an incomplete submit. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using form, check it fits: use it when a signup, invite or settings form with several required fields; you want every error listed at the top with a link to the field, plus a message under it; native browser validation should still work if the script does not run. Avoid it when a single field with one error line. use field.; you only need to group related controls under a legend. use fieldset.; a one-input search or newsletter box. use input-group.. Alternatives: @haze/field, @haze/fieldset.

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