Fieldset
Groups related controls under a real <fieldset> and <legend>: a profile section, a set of preferences, an address. Each control keeps its own Field.
Installation
Add Fieldset to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
Fieldset.tsxField.tsxLabel.tsxto your CK-UI folder (src/components/ck-ui by default)- Installs
@radix-ui/react-label@radix-ui/react-slotif your project does not have them yet
First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.
Manual installationInstall the packages and copy the files yourself.
Install the following dependencies
Run these commands in your terminal to install the required packages
Add the Field component
Fieldset imports ./Field, so add this file next to it
Add the Label component
Fieldset imports ./Label, so add this file next to it
Create or update your Fieldset component
Copy this code to create your Fieldset component
Test Your Component
- 1. Add the component to a test page
- 2. Check all props and variants work as expected
- 3. Verify responsive behavior
- 4. Test with different content/data
- 5. Ensure accessibility features work correctly
Notification Preferences
A bordered group of switches. Style the fieldset with className.
Disabled
disabled uses the native fieldset attribute, so every control inside is disabled by the browser, and Field.Root children reflect it in their labels.
Invalid
For an error about the group as a whole, set invalid and add Fieldset.Message. Mark the individual fields that are wrong with their own invalid.
Accessibility
- A native fieldset is a group; its legend is the group name, read when focus enters any control inside.
- Fieldset.Description and, while invalid, Fieldset.Message are referenced with
aria-describedbyon the fieldset. - The disabled attribute is native: controls inside cannot be focused or submitted.
requiredadds an asterisk and visually hidden "(required)" text to the legend. It does not validate; putrequiredon the fields.- Use a Fieldset for groups of related controls, not around a single control.
API Reference
Import with import * as Fieldset from "@/components/ui/Fieldset".
Fieldset.Root
The fieldset element. Other fieldset attributes (name, form) are passed through.
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | "boolean" | "false" | Native disabled; Field.Root children follow it. |
invalid | "boolean" | "false" | Shows Fieldset.Message and sets data-invalid. |
required | "boolean" | "false" | Required marker on the legend. |
className | "string" | "undefined" | Additional classes, merged last. |
Fieldset.Legend
The group name.
| Prop | Type | Default | Description |
|---|---|---|---|
className | "string" | "undefined" | Additional classes, merged last. |
Fieldset.Description
Help text for the group.
| Prop | Type | Default | Description |
|---|---|---|---|
className | "string" | "undefined" | Additional classes, merged last. |
Fieldset.Content
A column of controls with consistent spacing.
| Prop | Type | Default | Description |
|---|---|---|---|
className | "string" | "undefined" | Additional classes, merged last. |
Fieldset.Message
Error text for the group, rendered while invalid.
| Prop | Type | Default | Description |
|---|---|---|---|
showWhenValid | "boolean" | "false" | Also render while valid. |
className | "string" | "undefined" | Additional classes, merged last. |
Used in these blocks
Block families with at least one block built on this component. Each page previews its blocks and lists the components and packages they use.