Field
Form field wrapper with label, description, and error message
Installation
bunx @prototyperco/cli add fieldpnpm dlx shadcn@latest add https://prototyper-ui.com/r/field.jsonnpx shadcn@latest add https://prototyper-ui.com/r/field.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/field.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/field.jsonThis will add the following files to your project:
components/ui/field.tsx
Usage
import { Field, FieldLabel, FieldDescription } from "@/components/ui/field";<Field>
<FieldLabel>Email</FieldLabel>
<input />
<FieldDescription>Enter your email address.</FieldDescription>
</Field>Anatomy
<FieldSet>
<FieldLegend />
<Field>
<FieldLabel>{/* input, checkbox, or other control */}</FieldLabel>
<FieldContent>
<FieldDescription />
<FieldError />
</FieldContent>
</Field>
<FieldSeparator />
</FieldSet>Or with FieldGroup for grouped inputs:
<Field>
<FieldLabel />
<FieldGroup>{/* grouped inputs or controls */}</FieldGroup>
<FieldDescription />
<FieldError />
</Field>| Sub-component | data-slot | Purpose | Required |
|---|---|---|---|
Field | field | Root wrapper, provides layout and orientation | Yes |
FieldLabel | field-label | Label for the field control | No |
FieldTitle | field-label | Non-interactive label text (renders as div) | No |
FieldDescription | field-description | Helper/description text | No |
FieldError | field-error | Validation error message with role="alert" | No |
FieldGroup | field-group | Styled group container for composed inputs | No |
FieldContent | field-content | Content wrapper for description and error | No |
FieldSet | field-set | Fieldset element for grouping multiple fields | No |
FieldLegend | field-legend | Legend for a fieldset | No |
FieldSeparator | field-separator | Visual separator between fields | No |
Examples
Horizontal
Required
Error
With Select
With Checkbox
Field Group
Fieldset
Styling
Data Slots
Use data-slot attributes to target specific parts of the field:
| Slot name | Element |
|---|---|
field | Root wrapper div |
field-label | Label element |
field-description | Description paragraph |
field-error | Error message container |
field-group | Grouped input container |
field-content | Content wrapper (description + error) |
field-set | Fieldset element |
field-legend | Legend element |
field-separator | Visual separator |
field-separator-content | Text inside separator |
Customization Examples
/* Change label styling globally */
[data-slot="field-label"] {
@apply text-base font-semibold;
}
/* Style error messages */
[data-slot="field-error"] {
@apply text-xs font-medium;
}
/* Make field groups pill-shaped */
[data-slot="field-group"] {
@apply rounded-full;
}{
/* Override field orientation */
}
<Field orientation="horizontal">
<FieldLabel>Name</FieldLabel>
<input />
</Field>;API Reference
Field
Root wrapper that provides layout direction and grouping for form controls.
Prop
Type
All standard div props are forwarded via ...props.
FieldLabel
Label element that wraps or precedes a form control. Built on the Label component.
Prop
Type
All Label props are forwarded via ...props.
FieldTitle
Non-interactive label text rendered as a div instead of a <label>. Useful when the field does not contain a single focusable control.
Prop
Type
All standard div props are forwarded via ...props.
FieldDescription
Descriptive helper text rendered below the control. Automatically hidden when the field is in an invalid state.
Prop
Type
All standard p props are forwarded via ...props.
FieldError
Validation error message with animated reveal and live-region semantics.
Prop
Type
All standard div props are forwarded via ...props.
FieldGroup
Styled container for grouping multiple inputs or addon elements into a single bordered row.
Prop
Type
All standard div props are forwarded via ...props.
FieldContent
Flex column wrapper for description and error message content. Useful in horizontal layouts to keep description and error stacked beside the control.
Prop
Type
All standard div props are forwarded via ...props.
FieldSet
A <fieldset> element for grouping related fields. Automatically adjusts gap for checkbox-group and radio-group children.
Prop
Type
All standard fieldset props are forwarded via ...props.
FieldLegend
Legend element for a fieldset with size variant support.
Prop
Type
All standard legend props are forwarded via ...props.
FieldSeparator
Visual separator between fields, optionally displaying centered text content.
Prop
Type
All standard div props are forwarded via ...props.
Accessibility
Keyboard Interactions
| Key | Action |
|---|---|
Tab | Moves focus to the next focusable control |
ARIA Attributes
Fieldrenders withrole="group"to semantically group the label, control, and messages.FieldErrorrenders withrole="alert"andaria-live="polite"so error messages are announced by screen readers when they appear.data-orientationis set on the field root to indicate layout direction.data-invalidcan be set to indicate validation errors, propagating destructive text color to children.data-disabledis set when the field is disabled, and disabled styling propagates to child labels.FieldLabelwithrequiredadds a visual asterisk indicator.
Related
Related Components
A label for form controls with disabled and invalid state styling.
A horizontal or vertical separator built on Base UI.
A react-hook-form helper that wires Field, label, description, and error to a Controller in one component.
A text input with label and validation built on Base UI.
A number input with increment/decrement controls built on Base UI.