Form Field
The wrapper that gives a control its label, its hint and its error line, so every field in every form reads the same way.
import from ~/components/ui/form-field
Anatomy
Lowercase, no spaces. This becomes the repository name.
label + control + description
Three parts in a fixed order. The control is the child, everything around it is a prop.
Required
required
Adds the asterisk to the label. It is a visual marker, so still set required on the control itself.
Error
Enter a valid email address.
Pick a region before you continue.
error
The error replaces the description rather than stacking under it, so the field never grows two lines of hint. Set aria-invalid on the control at the same time.
Naming a GROUP of controls
as="group"
A radio group, a checkbox group, a segmented control: anything where several controls share one name. The legend names the set; each radio still has its own label.
In context
a whole form
One FormField per control keeps the label voice, the hint size and the error line identical down the form.
Rules
Do
Don't