Fieldset
Groups related form controls under a legend, on Ark UI's Fieldset. Its disabled and invalid reach every kit control inside.
Fieldset groups the controls of one part of a form (an address, a set of notification channels, the billing details) under a legend. It renders a real <fieldset> on top of Ark UI's Fieldset, so the browser's own rules apply: the legend names the group for assistive tech, and disabled turns off every control inside at once.
It sits one level above Field. A Field wires one control's label, description and error; a Fieldset names a group of them and carries the state they share. It never touches a field's own label or error, only its disabled and invalid.
import { Fieldset } from '@42-central/ui-react/fieldset';
import { TextInput } from '@42-central/ui-react/text-input';
<Fieldset legend="Personal information" description="Shown on your public profile.">
<TextInput label="Full name" />
<TextInput label="Email" type="email" />
</Fieldset>Playground
Fieldset
Dir
Presets
Props
Code
<Fieldset
legend="Personal information"
description="Shown on your public profile."
variant="default"
size="md"
/>Variants
variant picks the frame. default is the kit's form hairline alone, so the group takes the background it sits on. filled adds a wash behind the controls, for a group that has to stand out on a busy page. unstyled drops the frame and the padding: the legend becomes a heading over the controls, for a form that is already inside a card.
In the framed variants the legend sits on the border, where the browser places the first <legend> of a <fieldset>.
Code
<Fieldset variant="default" legend="default" description="Shown on your profile.">…</Fieldset>
<Fieldset variant="filled" legend="filled" description="Shown on your profile.">…</Fieldset>
<Fieldset variant="unstyled" legend="unstyled" description="Shown on your profile.">…</Fieldset>Disabled
disabled reaches every control inside, with no prop on any of them. Toggle it below: each form control the kit ships is in this one group.
Code
<Fieldset legend="Every control" disabled={disabled} invalid={invalid}>
<TextInput label="TextInput" />
<Select label="Select" data={projects} />
<TreeSelect label="TreeSelect" data={tree} />
<Checkbox label="Checkbox" />
{/* …and the rest of the form family */}
<Button type="submit">Save</Button>
</Fieldset>It gets there two ways. The <fieldset> disables every native <input>, <button>, <select> and <textarea> inside it, so nothing can be typed into, clicked or tabbed to. The kit's controls also read the group's state, and take the disabled look: Ark UI's Field inherits it, and the controls that render without a Field read it themselves.
A control follows the group whether it has a label or not: it dims in a disabled group and turns
red in an invalid one. It still needs an accessible name, so give it a label, wrap it in a
Field, or name it with aria-label.
A disabled control is left out of a form's submission. That is the browser's rule for a disabled <fieldset> too, so a group you disable while saving sends nothing. Use readOnly on the controls instead when their values must still be submitted.
Error
error is a message for the whole group, under the controls: "pick at least one", "this address couldn't be verified". Like Field's error, its presence sets invalid, and the group's invalid reaches every control inside, so they all turn red with it. A Field that sets its own invalid keeps it.
Code
<Fieldset
legend="Notifications"
description="Where should we reach you?"
error={picked.length === 0 ? "Pick at least one channel." : undefined}
>
<Checkbox label="Email" … />
<Checkbox label="Slack" … />
<Checkbox label="SMS" … />
</Fieldset>An error about one control still goes on that control's own error. Both can show at once.
Sizes
size uses Field's scale, xs to xl. It scales the legend, the description and error text, the padding and the gap between the controls. Set the controls' size to match.
Anatomy
For a layout the props don't cover, compose the parts: Fieldset.Root is the <fieldset>, .Legend its name, .Description the helper text, .Error the group's error. .Error renders only while the root is invalid. The controls go anywhere among them.
Each part takes a testId, rendered as data-testid on its own element. The ready-made Fieldset puts its testId on the <fieldset> and derives `${testId}-legend`, `${testId}-description` and `${testId}-error` for its parts. See the Testing guide.
Code
<Fieldset.Root testId="address" invalid>
<Fieldset.Legend testId="address-legend">Shipping address</Fieldset.Legend>
<Fieldset.Description testId="address-description">
We ship your swag here.
</Fieldset.Description>
<TextInput label="Street" />
<TextInput label="City" />
<Fieldset.Error testId="address-error">We couldn't verify this address.</Fieldset.Error>
</Fieldset.Root>.Legend, .Description and .Error take asChild. Fieldset and Fieldset.Root don't: the cascade of disabled belongs to a real <fieldset>, which another element can't stand in for.
API
Fieldset
Prop
Type
Every other prop (including id) forwards to the <fieldset>.
Fieldset.Root
Prop
Type
Fieldset.Legend, Fieldset.Description, Fieldset.Error
Prop
Type
Accessibility
- The root is a native
<fieldset>, which carries thegrouprole, and its legend names it. Ark also setsaria-labelledbyto the legend. - The description and, while invalid, the error describe the group through
aria-describedby. The error is a polite live region, so it is announced when it appears. disabledtakes every control out of the tab order and out of the accessibility tree's interactive controls, natively. The kit's controls also mark themselvesdata-disabled/aria-disabledwhere they draw their own elements (a slider thumb, a rating star, a tree picker's trigger).- RTL: the frame and the legend use logical padding, so the group mirrors under
dir="rtl".
Changelog
- #481
New Fieldset groups related controls under a legend, with
description,error,variantandsize - #481
Form controls follow the
disabledandinvalidstate of an enclosing Field or Fieldset, including dimming and turning red - #493
Controls with no
labelorFieldnow dim in a disabled Fieldset and turn red in an invalid one - #493
A Calendar's days can no longer be clicked or tabbed to inside a disabled Fieldset
Field
Label, description, and error scaffold for any form control — built on Ark UI's Field, so the accessible name, description, and invalid state wire themselves to whatever control you nest inside.
TextInput
A single-line text field with its label, description, and error built in — Input plus Field, the way every other control in the form family already works.