Field
Form field wrapper with label, description, and error message
Installation
pnpm 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
This component does not have standalone examples. It is used as a building block within TextField, NumberField, Checkbox, Radio Group, and other form components.
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 |
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;
}{/* 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>.
Prop
Type
All standard div props are forwarded via ...props.
FieldDescription
Descriptive helper text rendered below the control.
Prop
Type
All standard p props are forwarded via ...props.
FieldError
Validation error message with live-region semantics.
Prop
Type
All standard div props are forwarded via ...props.
FieldGroup
Styled container for grouping multiple inputs or controls.
Prop
Type
All standard div props are forwarded via ...props.
FieldContent
Flex column wrapper for description and error message content.
Prop
Type
All standard div props are forwarded via ...props.
FieldSet
A <fieldset> element for grouping related fields.
Prop
Type
All standard fieldset props are forwarded via ...props.
FieldLegend
Legend element for a fieldset.
Prop
Type
All standard legend props are forwarded via ...props.
FieldSeparator
Visual separator between fields, optionally with 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.data-disabledis set when the field is disabled, and disabled styling propagates to child labels.