Skip to documentation

Design system / Molecules

Molecule / Editing

FormField assembly

FormField coordinates one control's label, description, invalid state and error message. It uses react-hook-form state and generated IDs. The caller supplies the provider, schema, native form and save lifecycle.

Live example

Live preview

Current component with fictional data. Example changes are not persisted.

Example data only; no request is sent.

Responsibility

Control, label, description and error parts coordinate one field through Context and generated IDs. Form aliases FormProvider; it does not render a native form or implement submission. The caller provides those boundaries.

Public contract

The table describes supported inputs, exported parts and caller responsibilities. A callback supplies a command, such as saving a draft. These notes are maintained manually; check current source types before integration.

Maintained component API notes; current source is authoritative
Prop / partTypeRequirementResponsibility
name / control / renderControllerPropsFormFieldField path and render binding to react-hook-form.
FormFormProvider aliasProvider contractPass useForm methods; rendering a native form and submission is consumer-owned.
children / native propsFormItem, FormLabel, FormDescription, FormMessageAssemblyItem generates the base ID; label and feedback derive associations.
children / Slot propsFormControlOne slot-compatible controlInjects id, aria-describedby and aria-invalid; child must forward props.

API notes are curated documentation, not generated types. The source linked above is the current implementation; update these notes alongside API changes.

State and behavior

Identify which values the caller controls and which behavior the component or underlying primitive owns. A local example does not supply persistence, authorization or a complete product lifecycle.

Field and error state come from react-hook-form Context. FormItem generates an ID. useFormField combines field state with label/description/message IDs. No validation schema, mutation or route policy is defined here.

Dependencies

  • react-hook-form Controller, FormProvider, useFormContext and useFormState
  • React field/item Context and useId
  • Radix Slot
  • Label
  • cn()

Token and styling contract

These notes identify theme roles, utilities and direct style values used by the source. Direct colors or timings are implementation exceptions, not recommendations to bypass the theme.

text-destructive
Error label and message.
text-muted-foreground / text-sm
Description utilities.
grid / gap-2
Field layout.

Boundaries and limitations

  • Requires provider, field and item Context. Empty default Context objects mean the explicit fieldContext guard does not reliably detect every misuse.
  • FormControl references description/message IDs; consumers must render the corresponding feedback and forward Slot props correctly.
  • FormMessage favors error.message over children and returns null when neither yields content.

Where to make a change

Change association and error anatomy in form.tsx; validation schemas and submit lifecycle belong to consumers/controllers. Review IDs, Slot forwarding and Context hierarchy when evolving the contract.

Selected real uses

No product consumer is recorded in this entry's selected-use notes. The implementation and specimen establish availability, not adoption. These notes are not an exhaustive usage scan.

These traces describe selected uses, not every dependency. Repository-only paths are shown as references; only approved files have public source views.

Usage contract

import { Form, FormField, FormItem, FormLabel, FormControl, FormDescription, FormMessage } from "@/components/ui/form";
import { Input } from "@/components/ui/input";

<Form {...form}><FormField control={form.control} name="title" render={({ field }) => (
  <FormItem><FormLabel>Title</FormLabel><FormControl><Input {...field} /></FormControl>
    <FormDescription>Give the record a title.</FormDescription><FormMessage />
  </FormItem>
)} /></Form>

Illustrative consumer bindings, not a self-contained product workflow. Live examples supply only local state or explicit fictional props.

All molecules
Current components and theme tokens. Fictional example data. Source views refresh on deployment; authors maintain contract notes.