Field
Wraps a control with its label, description and error, and lays them out vertically or horizontally.
When to use
- Wrap any form control with its label, description and error, so the three stay together and line up across the form.
- Group several fields with
FieldGroup, or a set of checkboxes or radio buttons withFieldSetandFieldLegend.
When not to use
- A lone control with a label and nothing else: Label is enough.
- An input with icons or buttons inside its border: put an Input Group inside the Field.
Install
npx shadcn@latest add @clinia/fieldShown to everyone you invite.
Marketing (Sera)
Shown to everyone you invite.
Anatomy
Shown to everyone you invite.
- 1Field
data-slot="field"role=group · flex-col - 2Label
data-slot="field-label"text-sm · font-medium - 3Control
data-slot="input"border-input · border-destructive when invalid - 4Description
data-slot="field-description"text-sm · text-muted-foreground - 5Error (when invalid)
data-slot="field-error"text-sm · text-destructive
Clinia rules
vertical(default) stacks label, control, description and error.horizontalputs the label beside a checkbox or switch.responsiveswitches at theFieldGroupcontainer's breakpoint.data-invalidon the Field turns its label and error text destructive.FieldErroronly renders when it has a message.- The description says what the value is for or how it's formatted (
Shown to everyone you invite.). Keep hints out of the placeholder. - A choice card is a
FieldLabelwrapped around a horizontalFieldwith a radio or checkbox. The checked card takes a Trust border over abg-accent/15tint, and the others take the ink tint on hover. - On a marketing site, the Sera field matches the forms on clinia.com: a 42px box with an
inputborder and 8px corners, a 16px value, and the label above it in 16px sentence case. Focus takes theringborder and halo, as in product apps.
Do and don't
Starts with PAT, such as PAT-0142.
States: product (Luma)
Shown to everyone you invite.
Set when the workspace was created.
Toggle the site theme to review both themes.
States: marketing (Sera)
Shown to everyone you invite.
Set when the workspace was created.
Toggle the site theme to review both themes.
Accessibility
Built in
- Mark the field
data-invalidand the controlaria-invalidtogether: the first styles the label, the second the control and its focus ring. Fieldrendersrole="group".FieldErrorrendersrole="alert", so a new message is announced when it appears.
Your responsibility
- Link the parts yourself:
FieldLabelneedshtmlForset to the control'sid, and the control needsaria-describedbypointing at theFieldDescriptionandFieldErrorids. - Name a
FieldSetwith aFieldLegend, so the question is read with each option. - Don't show an error before the user has had a chance to answer. Validate on blur or on submit.
How to test
- Click each label: focus moves to its control.
- Tab into a field with a description: a screen reader reads the label, then the description.
- Submit with an error: the message appears under the control, is announced, and is read again when the field gets focus.
- Narrow the window with a
responsivefield: the label moves above the control and nothing overlaps.
API
Field
| Prop | Values | Default | Description |
|---|---|---|---|
| orientation | verticalhorizontalresponsive | vertical |
|
FieldError
| Prop | Values | Default | Description |
|---|---|---|---|
| errors | ({ message?: string; } | undefined)[] | – | Validation errors, such as a form library's. Duplicates show once and several messages render as a list; children replace them. |
FieldLegend
| Prop | Values | Default | Description |
|---|---|---|---|
| variant | labellegend | legend |
|
All other props come from the native div element.