Form
The state half of a form โ react-hook-form wired so that a control, its description and its error announce themselves as one field.
With react-hook-form
The whole grammar in one field: `FormField` binds the name and the rules, `FormItem` mints the id every other part reads, and the label, control, description and message wire themselves to it. Every other section on this page is a variation on these lines.
Usage
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
useFormField,
} from '@oceanic-hub/brand-system'<Form clearErrors={โฆ} control={โฆ} formState={โฆ} getFieldState={โฆ} getValues={โฆ} handleSubmit={โฆ} register={โฆ} reset={โฆ} resetField={โฆ} setError={โฆ} setFocus={โฆ} setValue={โฆ} setValues={โฆ} subscribe={โฆ} trigger={โฆ} unregister={โฆ} watch={โฆ}>
<FormField name={โฆ} render={โฆ}>
<FormItem>
<FormLabel>โฆ</FormLabel>
<FormControl>โฆ</FormControl>
<FormDescription>โฆ</FormDescription>
<FormMessage>โฆ</FormMessage>
</FormItem>
</FormField>
</Form>Composition
Use the following composition to build a Form:
Form
โโโ FormField ร3
โโโ FormItem
โโโ FormLabel
โโโ FormControl
โโโ FormDescription
โโโ FormMessagereact-hook-form is an optional peer dependency: nothing else in the package
imports it, so a surface that never reaches for this module never installs it.
What you are buying is the wiring, and the wiring is precisely what is lost silently when a
form is assembled by hand. FormItem mints one id; FormLabel points at the control,
FormControl puts the id on it, names the description and the message in
aria-describedby, and flips aria-invalid the moment the field fails. A label and a
paragraph sitting near each other look identical on screen and announce nothing.
It is the complement to Field, not a rival โ the same split Field's page states
from its side. Field owns layout and the validation semantics a layout has to express;
Form owns state. A settings screen with three controls and no resolver wants Field
alone; anything validated wants both, with FormField rendering a Field.
FormControl is a Slot, so it takes exactly one child element and hands it the ids โ
and that is why the field object does not simply spread onto everything. An <input>
takes {...field}; a Select wants value and onValueChange, a Checkbox and a
Switch checked and onCheckedChange. Spread field onto one of those and you get
an onChange nothing ever calls: the control moves and the form stays pristine.
An error is legible before it is coloured. FormMessage sets the words in ink beside a
stuck mark rather than in the tone โ a status colour measures 4.03:1 as body text, below AA
on the one string in a form nobody can skip โ and FormLabel is not recoloured at all,
because a field's name did not change meaning when its value became invalid. The mark carries
the severity, where the bar is 3:1 and the same colour passes. The CONTROL carries a solid
stuck border, and it needs nothing from this module to do it: FormControl sets
aria-invalid when the field fails, and every control in the field family paints that itself
(@OCE-1877), so a Form draws the line without a Field wrapped round it.
Upstream has moved on, and this shape is deliberately the older one. shadcn's
form documentation now composes react-hook-form's Controller directly with
Field / FieldLabel / FieldError, and offers TanStack Form and Formisch beside it.
Adopting that would be a base migration rather than a variant, which is the line
core-layer.md draws โ and it costs nothing here, because Field ships too, so the
composition upstream now recommends is already available without retiring this one.
Everything past the wiring stays react-hook-form's. Validation modes, a resolver, reset(),
useFieldArray โ this module adds nothing to any of them, and a second copy of their
documentation here would only be the staler one.
The invalid state
Pre-filled and pre-marked, because the state a form spends the least time in is the one worth looking at hardest. The label stays ink โ the field's name did not change meaning โ and the severity sits on the message's mark, where the contrast bar is 3:1 rather than 4.5:1. The border comes from the control: FormControl sets aria-invalid the moment the field fails, and every control in the family paints that itself, so a Form needs no Field around it to draw the line.
Controls that are not inputs
FormControl is a Slot: exactly one child, and it hands that child the ids. But the field object is shaped for a native input โ a Select wants value and onValueChange, a Checkbox and a Switch want checked and onCheckedChange. Spread field onto one of those and you get an onChange nothing ever calls.
Reading a field's state
useFormField is the hook the parts use on each other, and it is exported for the same reason: a counter, a strength meter or a save badge can read the field's name, its generated ids and its validity from inside the FormItem instead of being handed three props down from the render function.
API Reference
See the Form API page for every prop of every part, with types, defaults and the contract that pins them. It also documents useFormField โ exported alongside the parts, and signatures rather than props.