Field
Field gives one form control a label, a description and an error message, and connects all three to it.
<Field> <FieldLabel>Email</FieldLabel> <TextField type="email" /> <FieldDescription>We use this for receipts.</FieldDescription> <FieldError match={true}>That address is short.</FieldError></Field>Put each form control in a Field: a TextField, a TextArea, a Select, a Combobox, a NumberField, or a group of checkboxes or radios. The Field connects the label, the description and the error to the control, so a screen reader announces them together.
The parts always appear in the same order: label, control, description, error. The label sits directly above the control it names. The description says what to enter, and it stays visible when an error appears. The error says what went wrong.
Every Kookie control connects to the Field around it, so you add no ids or extra props. FieldLabel renders a real <label>, so clicking it moves focus to the control. FieldError shows only while the field is invalid, and a screen reader announces it when it appears.
You can show an error in three ways. For a browser check, set required or another constraint on the control and give FieldError a match such as valueMissing. For your own rules, pass a validate function to the Field, which returns a message or null. When your server rejects a value, set invalid on the Field and give FieldError the prop match={true}.
size on the Field sets the size of the label, the description, the error and the control together, although a control with its own size keeps it. disabled on the Field disables the control inside it.
In a group of checkboxes or radios, wrap each option in a FieldItem, which gives that option its own label and description. Leave room between options so that each one is easy to tap; gap="5" on a Stack keeps enough at every density.
The behaviour comes from Base UI's Field.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
Naming one control
Field
Field gives one form control a label, a description and an error message, and connects all three to it.
| Prop | Type | What it does |
|---|---|---|
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
size? | "1" | "2" | "3" | "4" | The size step for the whole field, from 1 to 4. |
Adding a description and an error
FieldControl— Every Kookie control already connects to the Field around it. Put the control directly inside the Field, and it gets its id, label and description automatically.orientation— A field with its label beside the control needs its own layout, because the error must line up under the control rather than under the label. To build one, pass your own grid to the Field'srenderprop.- A choice about where the error goes — The error always follows the description, below the control. Keeping one order means every field on a screen reads the same way.
- An error that replaces the description — Both are shown, because they say different things. The description says what to enter, and the error says what went wrong.
Form— AFormcomponent that assigns server errors to fields by name is not available yet. For now, setinvalidon each Field that your server rejects.