

# Fieldset

Groups related form controls under one label. It renders a real `<fieldset>` with a `<legend>`, so the group is announced by name and the browser does the rest: a `disabled` fieldset disables every form control inside it, with no per-control prop.

Use it for sets of related checkboxes or radios, an address block, or any cluster of fields that share a heading. For a single control, use that control's own `label`.

## Examples

### Default

`legend` is the shorthand for the legend text and `description` adds help text beneath it.

```tsx
import { Checkbox, Fieldset } from '@var-ui/react';

<Fieldset legend="Notifications" description="Choose how we reach you.">
  <Checkbox defaultChecked>Email</Checkbox>
  <Checkbox>SMS</Checkbox>
  <Checkbox>Push</Checkbox>
</Fieldset>
```

```astro
<!-- No Astro demo yet: see the Astro peer in the page text -->
```

```html
<!-- No HTML demo yet: use @var-ui/react -->
```

### Disabled

`disabled` is the native attribute. Every `input`, `select`, `textarea` and `button` inside is disabled and leaves the Tab order, including controls rendered by other var-ui components. The fieldset itself is dimmed through `:disabled` (also available as `data-disabled`).

```tsx
import { Checkbox, Fieldset, TextField } from '@var-ui/react';

<Fieldset legend="Billing address" description="Locked while the plan is archived." disabled>
  <TextField label="Street" />
  <Checkbox>Same as shipping</Checkbox>
</Fieldset>
```

```astro
<!-- No Astro demo yet: see the Astro peer in the page text -->
```

```html
<!-- No HTML demo yet: use @var-ui/react -->
```

### With error

`errorMessage` renders the message after the controls and marks the group invalid (`data-invalid`). Pass `invalid` to force the state either way.

```tsx
import { Checkbox, Fieldset } from '@var-ui/react';

<Fieldset legend="Interests" errorMessage="Pick at least one topic.">
  <Checkbox>Design</Checkbox>
  <Checkbox>Engineering</Checkbox>
  <Checkbox>Research</Checkbox>
</Fieldset>
```

```astro
<!-- No Astro demo yet: see the Astro peer in the page text -->
```

```html
<!-- No HTML demo yet: use @var-ui/react -->
```

### Horizontal

`orientation="horizontal"` lays the controls in a wrapping row. `gap` takes the full `space` scale — `none`, `xxs`, `xs`, `sm`, `md`, `lg`, `xl`, `xxl`, `xxxl`, `xxxxl` — mapped 1:1 to the `space.*` tokens.

```tsx
import { Checkbox, Fieldset } from '@var-ui/react';

<Fieldset legend="Days" orientation="horizontal" gap="lg">
  <Checkbox>Mon</Checkbox>
  <Checkbox>Tue</Checkbox>
  <Checkbox>Wed</Checkbox>
</Fieldset>
```

```astro
<!-- No Astro demo yet: see the Astro peer in the page text -->
```

```html
<!-- No HTML demo yet: use @var-ui/react -->
```

### Compound parts

For a custom legend node, use the parts as children. They can appear in any order: `Fieldset.Legend` is always rendered first, `Fieldset.Description` after it, and `Fieldset.Error` after the controls. Top-level Fragments are flattened, so wrapping parts in `<>…</>` still works.

```tsx
<Fieldset>
  <Fieldset.Legend>
    Shipping <Badge>Required</Badge>
  </Fieldset.Legend>
  <Fieldset.Description>Where should we send it?</Fieldset.Description>
  <TextField label="Street" />
  <Fieldset.Error>Enter a street</Fieldset.Error>
</Fieldset>
```

Set `legendHidden` to hide the legend visually while keeping it as the group's accessible name.

In Astro, use the `legend`, `description` and `error` slots (or the string props) of `Fieldset` from `@var-ui/astro`.

## Props

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| children | ReactNode | no |  | The controls, plus optional `Fieldset.Legend` / `Fieldset.Description` / `Fieldset.Error` parts. |
| description | ReactNode | no |  | Help text under the legend. |
| disabled | boolean \| undefined | no |  | Native `disabled`: disables every descendant form control and removes them from the Tab order. |
| errorMessage | ReactNode | no |  | Validation message after the controls. Implies `invalid`. |
| gap | "lg" \| "md" \| "none" \| "sm" \| "xl" \| "xs" \| "xxl" \| "xxs" \| "xxxl" \| "xxxxl" \| undefined | no | "sm" |  |
| invalid | boolean \| undefined | no |  | Marks the group invalid (`data-invalid`). `aria-invalid` is not allowed on a `fieldset` (group role), so the state is conveyed by the error text through `aria-describedby`. Derived from `errorMessage` unless set. |
| legend | ReactNode | no |  | Shorthand legend text. Use `<Fieldset.Legend>` as a child for a custom node. |
| legendHidden | boolean \| undefined | no | false | Visually hide the legend while keeping it as the group's accessible name. |
| orientation | "horizontal" \| "vertical" \| undefined | no | "horizontal" |  |

## Accessibility

- The group name comes from the `<legend>`, the first child of the `<fieldset>` (role `group`).
- `description` and `errorMessage` get ids and are referenced from the fieldset's `aria-describedby`, after any `aria-describedby` you pass.
- `aria-invalid` is not supported on the `group` role, so the invalid state is carried by the error text and the `data-invalid` styling hook rather than an ARIA attribute.
- `disabled` is native: descendant controls are disabled and skipped by Tab. Controls inside do not get a `data-disabled` hook from this; style them through `:disabled`.
- `form` and `name` pass through to the fieldset.

## Keyboard

The fieldset itself is not focusable and adds no key handling. Focus moves between the controls inside it as usual.

| Key             | Action                                                         |
| --------------- | -------------------------------------------------------------- |
| `Tab`           | Moves to the next enabled control, skipping disabled fieldsets |
| `Shift` + `Tab` | Moves to the previous enabled control                          |


> Also accepts all standard HTML attributes (ARIA attributes, event handlers, styles, …). Run `var-ui component fieldset --all-props` for the complete list.
