Skip to content

React Form Field and Label

A composable React form field that wires a label, a description and an error message to any control, ready for react-hook-form.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/field.json

We only use it to send receipts.

  • Field
  • FieldError
  • FieldLabel
  • FieldControl
  • FieldDescription
  • +9 more
  • +6 more

Using it in a form? See the react-hook-form and zod recipe.

Label, description and error

The error shows after the field has been visited and is invalid. Type a bad address and tab away.

We only use it to send receipts.

Files to copy

4 folders · 3 files · 4 packages
From theme/src/
  • components/field/
  • hooks/use-latest.ts
  • lib/{cn.ts, form.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/field.jsonRegistry item: field. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/button/
  • components/calendar/
  • components/checkbox/
  • components/color-picker/
  • components/combobox/
  • components/date-picker/
  • components/drawer/parts/sheet.tsx
  • components/file-upload/
  • components/input/
  • components/number-field/
  • components/otp-input/
  • components/radio-group/
  • components/rating/
  • components/segmented/
  • components/select/
  • components/slider/
  • components/spinner/
  • components/status-icons/
  • components/switch/
  • components/tags-input/
  • hooks/{use-controllable.ts, use-direction.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts, use-virtual-window.ts}
  • motion/{gate.ts, tokens.ts}
  • lib/{field-control-shell.tsx, field-size.ts, glide-highlight.tsx, group-segments.ts, ime.ts, math.ts, motion-props.ts, page-size.ts, popup-a11y.ts, popup-motion.ts, state-light.tsx, warn-once.ts}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/calendar.json https://lokendra-builds.github.io/sheenui/r/checkbox.json https://lokendra-builds.github.io/sheenui/r/color-picker.json https://lokendra-builds.github.io/sheenui/r/combobox.json https://lokendra-builds.github.io/sheenui/r/date-picker.json https://lokendra-builds.github.io/sheenui/r/file-upload.json https://lokendra-builds.github.io/sheenui/r/input.json https://lokendra-builds.github.io/sheenui/r/number-field.json https://lokendra-builds.github.io/sheenui/r/otp-input.json https://lokendra-builds.github.io/sheenui/r/radio-group.json https://lokendra-builds.github.io/sheenui/r/rating.json https://lokendra-builds.github.io/sheenui/r/segmented.json https://lokendra-builds.github.io/sheenui/r/select.json https://lokendra-builds.github.io/sheenui/r/slider.json https://lokendra-builds.github.io/sheenui/r/switch.json https://lokendra-builds.github.io/sheenui/r/tags-input.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Any control

Base UI controls such as Switch join the field on their own. FieldControl wires a native element or your own component and merges with its props (its own disabled, required, aria-invalid and id win). Pass a function to place the props yourself.

Email me about new features.

With react-hook-form

Field takes the error from the form library: Controller hands the control its ref, name, value and onBlur, and the message becomes FieldError's children. The preview below runs the same markup on plain state.

One size scale for buttons and fields

Input, Select, Combobox, NumberField, DatePicker, TagsInput, Textarea, OtpInput and the color field take size sm (32px), md (40px, default) or lg (48px), and so does Button: one height scale, so a button beside a field lines up at every size. On touch screens (any coarse pointer) sm and md grow to 44px.

Every control with react-hook-form

One Row helper, one line per control. Each control takes ref, name, onBlur and aria-invalid from the Controller field, so a failed validation focuses the right control; the value prop and the change handler are the only things that differ (checked and onCheckedChange for Checkbox and Switch, a Date or a DateRange for the pickers, an array for TagsInput and FileUpload).

Rating

Field props

PropTypeDefaultDescription
invalidbooleanfalseMarks the field invalid: the control gets aria-invalid and FieldError is shown.
disabledbooleanfalseDisables the control inside the field.
requiredbooleanfalseMarks the control required and adds an asterisk to the label.
controlIdstringgeneratedId of the control; a generated one is used when omitted.

Other parts

PropTypeDefaultDescription
FieldDescriptionp propsNoneHelper text under the control; listed in aria-describedby.
useField()FieldContextValue | nullNoneThe ids and state of the surrounding Field, for building your own parts.

FieldControl props

PropTypeDefaultDescription
children (required)ReactElement<Partial<FieldControlRenderProps>, string | JSXElementConstructor<any>> | ((props: FieldControlRenderProps) => ReactNode)NoneOne control element, or a function that gets the wiring props and returns the control.

FieldError props

PropTypeDefaultDescription
forceMatchbooleanfalseShow it even when the field is not marked invalid (for example a server error you render yourself).

FieldLabel props

PropTypeDefaultDescription
hintReactNodeNoneText shown after the label, such as "(optional)", muted.

Label props

PropTypeDefaultDescription
requiredbooleanfalseAdds an asterisk after the text. It is decorative: mark the control required for assistive tech.
hintReactNodeNoneText shown after the label, such as "(optional)", muted.

All exports on this page

  • Field — A form field wrapper that wires a label, a description and an error message to any control.
  • FieldControl — Wires the one control inside it to its Field: the element gets id, aria-describedby, aria-invalid, required and disabled.
  • FieldDescription — Muted helper text under the control; its id is added to the control's aria-describedby while it is rendered.
  • FieldError — The error message of a Field.
  • FieldLabel — The label of a Field: Label already pointing at the field's control, with the required asterisk.
  • Label — A text label for a control.
  • groupBlur — Wraps onBlur for a control made of several focusable parts: it fires only when focus leaves the whole group.
  • mergeRefs — Combine refs (callback or object) into one callback ref; undefined entries are skipped.
  • useField — The state of the surrounding Field (invalid, required, disabled, controlId).
  • useFocusProxyRef — A ref for a control made of several focusable parts (a radio group, a rating, an OTP field).
  • useMergedRef — mergeRefs as a hook: returns one stable callback ref that forwards the node to every ref passed in, always the latest ones.

Keyboard

KeysAction
Click the labelFocuses (or toggles) the control it names.
TabField adds no tab stops; focus order is the control's own.

Accessibility

  • FieldLabel is a real <label for> pointing at the control, so the control has an accessible name and a larger click target.
  • FieldDescription and FieldError ids are added to the control's aria-describedby only while they are rendered, merged with any aria-describedby the control already has.
  • FieldError is role="alert", so an error that appears after a submit or a blur is announced; it renders only while the field is invalid.
  • The required asterisk is aria-hidden; the control itself gets required, so assistive tech says it once.
  • Form libraries: every SheenUI input forwards ref, onBlur, name, required, disabled, aria-invalid and aria-describedby, so Field works with react-hook-form's Controller (pass invalid={fieldState.invalid} and the message as FieldError's children).

When to use the Field and Label

  • Use it as a react-hook-form field wrapper around a native input, a Slider or a Switch that does not draw its own label, so the label names the control and the description and error are read together with it.
  • Use it with react-hook-form: pass invalid={fieldState.invalid} to Field and put the validation message inside FieldError, and the control gets aria-invalid automatically.
  • Use it to build a settings row such as a webhook URL with helper text, where a FieldDescription explains the format and a FieldError appears only after a failed save.
  • Skip it when the control already takes label, description and error props; Input, Select and the other SheenUI form components wire those themselves, so wrapping them adds nothing.
  • Pair it with FieldControl around a native input or your own component, with Slider or Switch, which join the field on their own, and with the useField hook when writing your own field parts.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .