Fieldset
Native fieldset container with legend, optional description, card framing, and automatic disabled propagation.
pnpm dlx shadcn@latest add @haze/fieldset---
import { cn } from "../../../lib/haze/utils";
interface Props {
/** Legend heading associating all grouped controls inside the native fieldset. */
legend: string;
/** Optional helper copy displayed under the legend. */
description?: string;
/** Disables every descendant native form control inside this fieldset. */
disabled?: boolean;
/** plain renders unboxed vertical stack spacing; card frames the fieldset inside a hairline card. */
variant?: "plain" | "card";
class?: string;
[key: string]: unknown;
}
const {
legend,
description,
disabled = false,
variant = "plain",
class: className,
...rest
} = Astro.props;
---
<fieldset
{...rest}
disabled={disabled}
class={cn(
"m-0 grid min-w-0 gap-4",
variant === "card"
? "rounded-xl border border-border bg-card p-5 text-card-foreground"
: "border-0 p-0",
className,
)}
>
<legend
class={cn(
"text-sm/5 font-semibold tracking-[-0.01em] text-foreground",
variant === "card" ? "float-left mb-1 w-full p-0" : "mb-1 p-0",
)}
>
{legend}
</legend>
{description && <p class="-mt-2 text-[0.8125rem]/5 text-muted-foreground">{description}</p>}
<div class="grid min-w-0 gap-4">
<slot />
</div>
</fieldset>When to use
- Grouping related address, billing, or profile fields under a shared accessible legend
- Disabling an entire form section at once while keeping its description legible
- Separating multi-section settings forms into crisp card panels
When not to use
- Wrapping a single form control and label; use field instead
- Exclusive radio choices; use radio-group which supplies its own legend and items
Installation
Add the Haze registry to components.json once, then install Fieldset with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/fieldsetnpx shadcn@latest add @haze/fieldsetyarn dlx shadcn@latest add @haze/fieldsetbunx --bun shadcn@latest add @haze/fieldsetFirst 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 |
|---|---|---|---|
| legend* | string | – | Accessible group heading rendered as the semantic <legend>. |
| description | string | – | Supporting helper text displayed beneath the legend. |
| disabled | boolean | false | Disables every native control inside the fieldset without dimming the description. |
| variant | "plain" | "card" | "plain" | plain spaces controls without borders; card wraps the group in an elevated hairline surface. |
| class | string | – | Extra classes on the <fieldset>. |
Keyboard interactions
- Tab
- Moves focus through enabled controls inside the fieldset, skipping the whole section when disabled
Accessibility
- Emits a native <fieldset> and <legend> so assistive technologies announce the section context for every child input.
- Setting disabled disables descendant controls natively while preserving legend and helper text contrast.
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 "Fieldset" with `npx shadcn@latest add @haze/fieldset`. 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 Fieldset from "@/components/haze/ui/fieldset.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/fieldset.md
Customize with real content
Adapt the Haze fieldset ui for our product. Replace the demo values of these props with our real content: legend, description, disabled, variant, class. Keep the layout, the heading level rules and these accessibility details: Emits a native <fieldset> and <legend> so assistive technologies announce the section context for every child input. Setting disabled disables descendant controls natively while preserving legend and helper text contrast. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using fieldset, check it fits: use it when grouping related address, billing, or profile fields under a shared accessible legend; disabling an entire form section at once while keeping its description legible; separating multi-section settings forms into crisp card panels. Avoid it when wrapping a single form control and label; use field instead; exclusive radio choices; use radio-group which supplies its own legend and items. Alternatives: @haze/field, @haze/frame, @haze/radio-group.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.