Fieldset
A fieldset with accessible legend for grouping related form controls
Loading...
Installation
pnpm dlx shadcn@latest add https://prototyper-ui.com/r/fieldset.jsonnpx shadcn@latest add https://prototyper-ui.com/r/fieldset.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/fieldset.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/fieldset.jsonThis will add the following files to your project:
components/ui/fieldset.tsx
Usage
import { Fieldset, FieldsetLegend } from "@/components/ui/fieldset"
<Fieldset>
<FieldsetLegend>Preferences</FieldsetLegend>
{/* form controls */}
</Fieldset>Anatomy
<Fieldset>
<FieldsetLegend />
{/* Field, Checkbox, RadioGroup, or other controls */}
</Fieldset>| Sub-component | data-slot | Purpose | Required |
|---|---|---|---|
Fieldset | fieldset | Root container, renders <fieldset> with ARIA | Yes |
FieldsetLegend | fieldset-legend | Accessible legend, renders <div> with ARIA tie | Yes |
Examples
Disabled
Loading...
With Fields
Loading...
Styling
Data Slots
Use data-slot attributes to target specific parts of the fieldset:
| Slot name | Element |
|---|---|
fieldset | Root fieldset container |
fieldset-legend | Legend text |
Customization Examples
/* Tighter fieldset spacing */
[data-slot="fieldset"] {
@apply gap-4;
}
/* Style the legend as a smaller label */
[data-slot="fieldset-legend"] {
@apply text-sm text-muted-foreground;
}{/* Label-sized legend variant */}
<Fieldset>
<FieldsetLegend variant="label">Settings</FieldsetLegend>
{/* ... */}
</Fieldset>API Reference
Fieldset
Root container that groups related form controls. Renders a <fieldset> element.
Prop
Type
All Base UI Fieldset.Root props are forwarded via ...props.
FieldsetLegend
Accessible legend that is automatically associated with the fieldset. Renders a <div> element.
Prop
Type
All Base UI Fieldset.Legend props are forwarded via ...props.
Accessibility
ARIA Attributes
Fieldsetrenders a<fieldset>element with native grouping semantics.FieldsetLegendrenders a<div>but is automatically associated with the fieldset viaaria-labelledby.- When
disabledis set on the fieldset, all nested controls inherit the disabled state. - Screen readers announce the legend as the group label when navigating into the fieldset.