# Fieldset

> Native fieldset container with legend, optional description, card framing, and automatic disabled propagation.

- Kind: ui · Category: Forms · Interactivity: native
- Install: `npx shadcn@latest add @haze/fieldset`
- File: `src/components/haze/ui/fieldset.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/fieldset

## Use 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 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
- [field](https://hazeui.com/ui/field.md)
- [frame](https://hazeui.com/ui/frame.md)
- [radio-group](https://hazeui.com/ui/radio-group.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| legend | `string` |  | yes | Accessible group heading rendered as the semantic <legend>. |
| description | `string` |  | no | Supporting helper text displayed beneath the legend. |
| disabled | `boolean` | false | no | Disables every native control inside the fieldset without dimming the description. |
| variant | `"plain" \| "card"` | "plain" | no | plain spaces controls without borders; card wraps the group in an elevated hairline surface. |
| class | `string` |  | no | Extra classes on the <fieldset>. |

## 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.
- Key Tab: Moves focus through enabled controls inside the fieldset, skipping the whole section when disabled

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Group company name and tax ID fields inside a card Fieldset labeled Billing address
- Wrap locked workspace settings in a disabled Fieldset

## Source

```astro
---
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>
```
