$npx @dinachi/cli@latest add fieldset
FieldsetLegenddisabledname-fields.tsx
import { Field, FieldControl, FieldLabel } from "@/components/ui/field"
import { Fieldset, FieldsetLegend } from "@/components/ui/fieldset"
export function NameFields() {
return (
<Fieldset className="w-full max-w-sm">
<FieldsetLegend>Personal Information</FieldsetLegend>
<Field>
<FieldLabel>First Name</FieldLabel>
<FieldControl placeholder="John" />
</Field>
<Field>
<FieldLabel>Last Name</FieldLabel>
<FieldControl placeholder="Doe" />
</Field>
</Fieldset>
)
}Usage
import { Field, FieldControl, FieldLabel } from "@/components/ui/field"
import { Fieldset, FieldsetLegend } from "@/components/ui/fieldset"
export function Shipping() {
return (
<Fieldset>
<FieldsetLegend>Shipping address</FieldsetLegend>
<Field name="street">
<FieldLabel>Street</FieldLabel>
<FieldControl />
</Field>
<Field name="city">
<FieldLabel>City</FieldLabel>
<FieldControl />
</Field>
</Fieldset>
)
}Examples
A legend over a group of fields.
import { Fieldset, FieldsetLegend } from '@/components/ui/fieldset';
import { Field, FieldLabel, FieldControl } from '@/components/ui/field';
export function Example() {
return (
<Fieldset className="w-full max-w-sm">
<FieldsetLegend>Personal Information</FieldsetLegend>
<Field>
<FieldLabel>First Name</FieldLabel>
<FieldControl placeholder="John" />
</Field>
<Field>
<FieldLabel>Last Name</FieldLabel>
<FieldControl placeholder="Doe" />
</Field>
</Fieldset>
);
}Split a long form into labelled sections.
import { Fieldset, FieldsetLegend } from '@/components/ui/fieldset';
import { Field, FieldLabel, FieldControl } from '@/components/ui/field';
export function Example() {
return (
<div className="w-full max-w-sm space-y-4">
<Fieldset>
<FieldsetLegend>Account Details</FieldsetLegend>
<Field>
<FieldLabel>Email</FieldLabel>
<FieldControl type="email" placeholder="you@example.com" />
</Field>
<Field>
<FieldLabel>Username</FieldLabel>
<FieldControl placeholder="johndoe" />
</Field>
</Fieldset>
<Fieldset>
<FieldsetLegend>Address</FieldsetLegend>
<Field>
<FieldLabel>Street</FieldLabel>
<FieldControl placeholder="123 Main St" />
</Field>
<Field>
<FieldLabel>City</FieldLabel>
<FieldControl placeholder="New York" />
</Field>
</Fieldset>
</div>
);
}Notes
Agents
Not a control of its own. The agent reports the legend as in on each control inside, so two City fields stay distinct: one in Shipping address, one in Billing address.
API
disabled
Disables every control inside, native inputs and Fields.agent
boolean = falserenderReactElement
Swap the element, keep the behaviour.children
Also the container name the agent reports for each control inside.agent
ReactNodeAccessibility
- A native
<fieldset>; the group and its disabled state are announced. FieldsetLegendis a freely styleable<div>that names the fieldset via aria-labelledby.- Disabled, the browser disables native controls inside and every Field reads the state.