Components
Fieldset
Group related fields with a native fieldset, legend, and shared disabled state.
Fieldset groups related fields and renders a native <fieldset>. Legend renders the native
<legend> that names the group. Both are exported from @orkest/ui/client.
Use Fieldset for address blocks, radio groups, and settings sections that should be disabled
together.
Basic usage#
import { Box } from '@orkest/ui';
import { Field, FieldLabel, Fieldset, Input, Legend } from '@orkest/ui/client';
export function Example() {
return (
<Box width="100%" maxWidth="22rem">
<Fieldset>
<Legend>Shipping address</Legend>
<Field>
<FieldLabel>Street</FieldLabel>
<Input placeholder="221B Baker Street" />
</Field>
<Field>
<FieldLabel>City</FieldLabel>
<Input placeholder="London" />
</Field>
</Fieldset>
</Box>
);
}The browser derives the group name from the first <legend>. Fieldset also registers the legend
id in aria-labelledby for consistent behavior across browsers and assistive technology.
Disabled group#
Disabling a Fieldset disables every native control inside it and propagates the state to nested
Field components.
import { Box } from '@orkest/ui';
import { Field, FieldLabel, Fieldset, Input, Legend } from '@orkest/ui/client';
export function Example() {
return (
<Box width="100%" maxWidth="22rem">
<Fieldset disabled>
<Legend>Billing contact</Legend>
<Field>
<FieldLabel>Name</FieldLabel>
<Input defaultValue="Grace Hopper" />
</Field>
<Field>
<FieldLabel>Email</FieldLabel>
<Input defaultValue="grace@example.com" />
</Field>
</Fieldset>
</Box>
);
}Radio groups#
Pair Fieldset and Legend with Field and FieldLabel to name a radio group. The group receives
the label through aria-labelledby, and the required state is propagated to the radios.
import { useState } from 'react';
import { Box } from '@orkest/ui';
import {
Field,
FieldDescription,
FieldLabel,
Fieldset,
Legend,
Radio,
RadioGroup,
} from '@orkest/ui/client';
export function Example() {
const [frequency, setFrequency] = useState('weekly');
return (
<Box width="100%" maxWidth="22rem">
<Fieldset>
<Legend>Email digest</Legend>
<Field required>
<FieldLabel>Frequency</FieldLabel>
<RadioGroup value={frequency} onValueChange={setFrequency}>
<Radio value="daily" label="Daily" />
<Radio value="weekly" label="Weekly" />
<Radio value="monthly" label="Monthly" />
</RadioGroup>
<FieldDescription>Choose when we send your summary.</FieldDescription>
</Field>
</Fieldset>
</Box>
);
}Props#
Fieldset#
| Prop | Type | Default |
|---|---|---|
disabled | boolean | false |
| Disables every control in the group and nested fields. | ||
aria-labelledby | string | — |
| Overrides the legend association when a custom name is needed. | ||
native attributes | FieldsetHTMLAttributes<HTMLFieldSetElement> | — |
| Class names, event handlers, and refs are forwarded to the fieldset element. | ||
Legend#
| Prop | Type | Default |
|---|---|---|
id | string | — |
| Legend id. Generated and registered with the surrounding Fieldset. | ||
native attributes | HTMLAttributes<HTMLLegendElement> | — |
| Class names and refs are forwarded to the legend element. | ||
Accessibility#
Fieldsetrenders a native<fieldset>;Legendrenders a native<legend>.- The legend names the group and is announced when entering the group.
disableduses the native fieldset attribute, so all controls inside become disabled.- Nested fields receive the disabled state through context and use native disabled attributes.
- Prefer one legend per fieldset and place it as the first child.