Fieldset
Groups related controls under one legend. Renders a native fieldset, so
disabled cascades to every control inside it without any JavaScript.
import { Fieldset } from "antlitz";
API
| Prop | Type | Default |
|---|---|---|
| description | ReactNode | — |
| error | ReactNode | — |
| legend | ReactNode | — |
| orientation | "vertical" | "horizontal" | vertical |
| required | boolean | false |
The props mirror Field — legend where Field has label. required is
presentational here: a fieldset has no required attribute, and nothing is
propagated to the children.
Usage
export function Basic() {
return (
<Fieldset
legend="Visibility"
description="Only affects new posts."
className="w-full max-w-xs"
>
<Field orientation="horizontal" label="Public">
<Radio name="visibility" value="public" defaultChecked />
</Field>
<Field orientation="horizontal" label="Private">
<Radio name="visibility" value="private" />
</Field>
</Fieldset>
);
}Orientation
export function Orientation() {
return (
<Fieldset legend="Density" orientation="horizontal" className="w-full">
<Field orientation="horizontal" label="Compact">
<Radio name="density" value="compact" defaultChecked />
</Field>
<Field orientation="horizontal" label="Cosy">
<Radio name="density" value="cosy" />
</Field>
<Field orientation="horizontal" label="Roomy">
<Radio name="density" value="roomy" />
</Field>
</Fieldset>
);
}Validation
export function Validation() {
return (
<Fieldset
legend="Pick at least one"
required
error="Select a channel to continue."
className="w-full max-w-xs"
>
<Field orientation="horizontal" label="Email">
<Checkbox name="channel" value="email" aria-invalid />
</Field>
<Field orientation="horizontal" label="SMS">
<Checkbox name="channel" value="sms" aria-invalid />
</Field>
</Fieldset>
);
}The error is wired to the fieldset through aria-describedby, so it is
announced when focus enters the group.
Fieldset does not set aria-invalid on individual controls — it never inspects
its children, which may be nested arbitrarily deep. Set it per control, or let
a form library do it.
Disabled
export function Disabled() {
return (
<Fieldset
legend="Delivery speed"
description="Unavailable for your region."
disabled
className="w-full max-w-xs"
>
<Field orientation="horizontal" label="Standard">
<Radio name="speed" value="standard" defaultChecked />
</Field>
<Field orientation="horizontal" label="Express">
<Radio name="speed" value="express" />
</Field>
</Fieldset>
);
}disabled disables every control inside natively. The legend and labels dim to
match.
Radio groups
Radios sharing a name already form a group with arrow-key navigation and
single selection — that behaviour is native and needs no component. What a bare
group lacks is a name and somewhere for an error to live, which is what the
legend and error supply.
There is no separate RadioGroup for that reason. Fieldset groups checkboxes
and arbitrary fields equally well; a radio-specific component would only add
name propagation, which would be wrong for the other cases.