Fieldset
Fieldsets group multiple fields together with a label. This is a light wrapper over the native fieldset and legend elements, but makes the legend element easily stylable.
Installation
Base UI components are all available as a single package.
npm install @base-ui-components/react
Once you have the package installed, import the component.
import { Fieldset } from '@base-ui-components/react/Fieldset';
Anatomy
Fieldsets are composed of two components:
<Fieldset.Root />
renders thefieldset
element.<Fieldset.Legend />
renders a label for the fieldset.
<Fieldset.Root>
<Fieldset.Legend />
</Fieldset.Root>
Usage with Fields
Field
components are placed inside the Fieldset
component.
<Fieldset.Root>
<Fieldset.Legend>Account details</Fieldset.Legend>
<Field.Root>
<Field.Label>Name</Field.Label>
<Field.Control />
</Field.Root>
<Field.Root>
<Field.Label>Address</Field.Label>
<Field.Control />
</Field.Root>
<Field.Root>
<Field.Label>Bio</Field.Label>
<Field.Control render={<textarea />} />
</Field.Root>
</Fieldset.Root>
API Reference
FieldsetRoot
The foundation for building custom-styled fieldsets.
Prop | Type | Default | Description |
---|---|---|---|
className | union | Class names applied to the element or a function that returns them based on the component's state. | |
render | union | A function to customize rendering of the component. |
FieldsetLegend
Renders an element that labels the fieldset.
Prop | Type | Default | Description |
---|---|---|---|
className | union | Class names applied to the element or a function that returns them based on the component's state. | |
render | union | A function to customize rendering of the component. |