Components
Fieldset
Fieldset is used to group and label fields that naturally belong together, such as date fields or address fields. The component helps organize information, make forms more manageable, and improve accessibility for screen readers.
It is common to get confused between fieldset and field. A good rule of thumb is that fieldset is a set of fields
HTML
Unable to parse html
const PreviewEn = () => { return ( <Fieldset> <Fieldset.Legend>Which fjord arm do you live by?</Fieldset.Legend> <Fieldset.Description> The choice will help us improve the content we show you. </Fieldset.Description> <Radio label='Barsnesfjorden' name='radio' value='barsnesfjorden' /> <Radio label='Eidsfjorden' name='radio' value='eidsfjorden' /> <Radio label='None of these' name='radio' value='none-of-these' /> </Fieldset> ); }; render(<PreviewEn />)
Usage
Use ds-fieldset on the <fieldset> element.
Examples
With checkbox or radio
Build the group with checkbox or radio as children of <fieldset>. This also applies when the group has only one element.
HTML
Unable to parse html
const WithCheckboxEn = () => { return ( <Fieldset> <Fieldset.Legend>Do you accept the terms?</Fieldset.Legend> <Checkbox label='Yes, I accept' value='agree' /> </Fieldset> ); }; render(<WithCheckboxEn />)
Multiple field types
A fieldset can also group other fields, for example field with input and select.
HTML
Unable to parse html
const WithFieldsEn = () => { return ( <Fieldset> <Fieldset.Legend>Personal information</Fieldset.Legend> <Fieldset.Description> Fill in your personal information below. </Fieldset.Description> <Field> <Label>First name</Label> <Input /> </Field> <Field> <Label>Gender</Label> <Select> <Select.Option value='male'>Male</Select.Option> <Select.Option value='female'>Female</Select.Option> <Select.Option value='other'>Other</Select.Option> </Select> </Field> </Fieldset> ); }; render(<WithFieldsEn />)
Readonly
Fields with the readonly attribute are included in the tab order. Users can copy the content but not edit it. Information is included when the form is submitted.
Readonly fields can be confusing for some users. Not everyone will understand why they cannot change the content of the field. We therefore recommend avoiding readonly as much as possible.
HTML
Unable to parse html
const ReadOnlyEn = () => { return ( <Fieldset> <Fieldset.Legend>Which district do you live in?</Fieldset.Legend> <Fieldset.Description> Trondheim is divided into four districts </Fieldset.Description> <Radio label='Østbyen' value='ostbyen' name='city' readOnly /> <Radio label='Lerkendal' value='lerkendal' name='city' readOnly /> <Radio label='Heimdal' value='heimdal' name='city' readOnly checked /> <Radio label='Midtbyen' value='midtbyen' name='city' readOnly /> </Fieldset> ); }; render(<ReadOnlyEn />)
CSS variables and data attributes
Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.
| Name | Value |
|---|---|
| --dsc-fieldset-gap | var(--ds-size-4) |
| --dsc-fieldset-description-color | var(--ds-color-neutral-text-subtle) |
| Name | Value |
|---|---|
| data-field | description |
React
- variant
- Description
Adjusts styling for paragraph length
- Type
"long" | "default" | "short"- Default
'default'
- asChild
- Description
Change the default rendered element for the one passed as a child, merging their props and behavior.
- Type
boolean- Default
false
| Name | Type | Default | Description |
|---|---|---|---|
| variant | "long" | "default" | "short" | 'default' | Adjusts styling for paragraph length |
| asChild | boolean | false | Change the default rendered element for the one passed as a child, merging their props and behavior. |