Fieldset
The Fieldset provides an accessible way to group a set of form components. It handles the legend, description, orientation, error message, as well as the required, and disabled states. The Fieldset determines the presentation and selection of the items in the list.
Quick Start
- Installation
npm install @adaptavant/eds-core- Import
import { Fieldset } from '@adaptavant/eds-core';
Legend
Describes the purpose of the field.
{/* legend */}
<Fieldset legend="Preferred contact method">
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
Description
A description of the field. Provides a hint such as specific requirements for what to choose.
{/* Description */}
<Fieldset
description="Please check all that apply."
legend="Preferred contact method"
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
Orientation
Indicates whether the orientation of the form controls inside of the Fieldset are horizontal or vertical (defaults to vertical).
<Fieldset
legend="Preferred contact method"
description="Please check all that apply."
orientation="horizontal"
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
Required fields
Use the isRequired prop if user input is required on the field before form submission.
{/* isRequired */}
<Fieldset
description="Please check all that apply."
legend="Preferred contact method"
isRequired
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
Disabled
Use the isDisabled prop to show that form controls within a Fieldset aren't usable.
{/* isDisabled */}
<Fieldset
description="Please check all that apply."
legend="Preferred contact method"
isDisabled
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
Error Messages
Use the errorMessage prop to show that form controls within a Fieldset are in an error state.
The
errorMessageprop is ⚠️ deprecated and will be removed in a future release, please check the FieldMessage section to add error state.
{/* errorMessage */}
<Fieldset
description="Please check all that apply."
legend="Preferred contact method"
errorMessage="Please select at least one option."
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
Status
Use the status prop to indicate whether a field is in an error or warning state.
<Stack className="gap-4">
<Fieldset
description="Please check all that apply."
legend="Preferred contact method"
status="error"
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
<Fieldset
description="Please check all that apply."
legend="Preferred contact method"
status="warning"
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
</Stack>
FieldMessage
Use the status prop to signal that controls in a Fieldset are in an error or warning state, and fieldMessage to provide the reason.
<Stack className="gap-4">
<Fieldset
description="Please check all that apply."
legend="Preferred contact method"
status="error"
fieldMessage="Please select at least one option."
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
<Fieldset
description="Please check all that apply."
legend="Preferred contact method"
status="warning"
fieldMessage="Please select at least one option."
>
<Checkbox label="Phone" name="option" size="standard" value="phone" />
<Checkbox label="Email" name="option" size="standard" value="email" />
<Checkbox label="SMS" name="option" size="standard" value="sms" />
</Fieldset>
</Stack>
API Reference
Fieldset
| Prop | Type | Description | Default |
|---|---|---|---|
children | React.ReactNode | The form elements to be grouped together, such as Field, Checkbox, Radio or TextInput. | _ |
description? | React.ReactNode | Additional text that appears below the legend to provide context or instructions for the entire group of form controls. | _ |
id? | string | A unique identifier for the fieldset, useful for form accessibility and targeting with CSS or JavaScript. | _ |
isDisabled? | boolean | When set to true, disables all form controls within the fieldset, preventing user interaction and applying a disabled visual style. | false |
isRequired? | boolean | Whether user input is required on the input before form submission. | false |
legend | React.ReactNode | The title or heading for the fieldset that clearly identifies the purpose of the grouped form controls. | _ |
errorMessage? | React.ReactNode | Text displayed when validation fails, highlighting what needs to be corrected. Adds visual error styling and announces the error to screen readers. | _ |
status? | error | warning | Use the status prop to indicate whether a field is in an error or warning state. | _ |
fieldMessage? | string | Use the status and fieldMessage props to convey why the field is in an error or warning state. The message is announced on focus for screen readers. | |
orientation? | 'horizontal' | 'vertical' | Controls the layout direction of the form elements within the fieldset - either side-by-side (horizontal) or stacked (vertical). | 'vertical' |
Style API
Our design system components include style props that allow you to easily customize different parts of each component to match your design needs.
Please refer to the Style API documentation for more insights.
Fieldset parts
{/* Styling the legend and description */}
<Fieldset
className="border-2 border-accent rounded-lg p-4"
classNames={{
legend: 'text-primary bg-critical px-2 py-1 font-bold mb-0',
description: 'text-secondary italic',
wrapper: 'px-2 py-4 gap-y-0 bg-positive'
}}
legend="Contact Information"
description="Please fill in your contact details"
>
<Stack className="items-stretch w-full gap-2">
<Field label="Name">
<TextInput />
</Field>
<Field label="Email">
<TextInput />
</Field>
</Stack>
</Fieldset>
{/* Styling error states */}
<Fieldset
classNames={{
errorTrack: 'bg-caution items-center p-2 rounded-lg',
errorIcon: 'fill-primary',
errorMessage: 'text-neutral font-strong'
}}
legend="Payment Details"
errorMessage="Please complete all required fields"
>
<Stack className="items-stretch w-full gap-2">
<Field label="Card Number">
<TextInput />
</Field>
<Field label="Expiry Date">
<TextInput />
</Field>
</Stack>
</Fieldset>
| Stylable Parts | Description |
|---|---|
| legend | The text that describes the purpose of the fieldset group. |
| description | The hint text that provides additional information about the fieldset. |
| wrapper | The container that wraps the fieldset content. |
| errorTrack | The container for the error message and icon. |
| errorIcon | The icon displayed when the fieldset has an error. |
| errorMessage | The text that displays the error message. |