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.
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>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).
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>With error
errorMessage renders the message after the controls and marks the group invalid (data-invalid). Pass invalid to force the state either way.
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>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.
import { Checkbox, Fieldset } from '@var-ui/react';
<Fieldset legend="Days" orientation="horizontal" gap="lg">
<Checkbox>Mon</Checkbox>
<Checkbox>Tue</Checkbox>
<Checkbox>Wed</Checkbox>
</Fieldset>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.
<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
Accessibility
- The group name comes from the
<legend>, the first child of the<fieldset>(rolegroup). descriptionanderrorMessageget ids and are referenced from the fieldset’saria-describedby, after anyaria-describedbyyou pass.aria-invalidis not supported on thegrouprole, so the invalid state is carried by the error text and thedata-invalidstyling hook rather than an ARIA attribute.disabledis native: descendant controls are disabled and skipped by Tab. Controls inside do not get adata-disabledhook from this; style them through:disabled.formandnamepass 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 |