Field
A form field wrapper composing label, description, and error display.
Default
Your full name as it appears on your ID.
Sizes
Input and Textarea accept a size prop (sm, md, lg) that controls height, padding, and border-radius.
With Error
Horizontal
With Textarea
Maximum 200 characters.
Control Box
FieldControl is the box a control sits in. Put one Input, Textarea or Select
inside: the control fills the box and goes bare, and the box draws the fill, the
edge, the focus ring (2px on keyboard focus) and the invalid look, read from the
control's aria-invalid. Pass tall for a Textarea, so the box grows with its
text. FieldLabel optional adds the "optional" mark. Without FieldControl,
Field renders exactly as above.
As it appears on your ID.
Glass and the Error Colour
Glass is off by default: the box is solid, with the shared control edge. Inside
data-glass="on" (see Glass) it takes the glass layer's
control fill, hover fill, ring, ink and blur. The error colour is a theme value,
field.error-color (unset, --text-error), so a plain page draws the error line
in red. Over a photo, red sinks into warm colours, so under glass the error line
and the invalid edge take the glass layer's on-photo ink, and the icon and the
edge carry the error.
In Five Looks
Field with its control box, valid and invalid, in each look on the theme picked in
the docs. The Photo looks turn glass on over a photo. The specimen binds the kit's
sizes and inks through the field tokens, as a theme would (see Theming below).
Theming
A theme sets the label (size, weight, case, tracking, colour, the "optional"
mark), the hint, the error line and the control box through the field
component tokens. Each falls back to the look above, so a theme that binds none
of them draws Field unchanged. See
Component Tokens.
components:
field:
label-font-size: "9px"
label-text-transform: uppercase
label-letter-spacing: "0.12em"Installation
npx visor add fieldThis copies two files into your project:
components/ui/field/field.tsx— the componentcomponents/ui/field/field.module.css— the styles
Usage
import { Field, FieldLabel, FieldDescription, FieldError } from '@/components/ui/field/field';
import { Input } from '@/components/ui/input/input';
<Field>
<FieldLabel htmlFor="name">Name</FieldLabel>
<Input id="name" placeholder="Jane Doe" />
<FieldDescription>Your full name as it appears on your ID.</FieldDescription>
</Field>API Reference
FieldProps
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'vertical' | 'horizontal' | 'vertical' | Layout direction of the field group. |
className | string | — | Additional CSS class names to merge onto the element. |
FieldLabelProps
| Prop | Type | Default | Description |
|---|---|---|---|
optional | boolean | false | Renders " optional" after the label text, inside the label, so the accessible name includes it. |
FieldControlProps
| Prop | Type | Default | Description |
|---|---|---|---|
tall | boolean | false | Lets the box grow with its content, for a Textarea. |
children | React.ReactNode | — | One Input, Textarea or Select. It fills the box and goes bare; the box draws the fill, edge, focus ring and invalid look (from the control's aria-invalid). |
FieldErrorProps
| Prop | Type | Default | Description |
|---|---|---|---|
errors | Array<{ message?: string } | undefined> | — | Array of error objects to display. Duplicates are deduplicated by message. |
children | React.ReactNode | — | Custom error content. Takes precedence over the errors prop. |
Sub-components
| Component | Element | Purpose |
|---|---|---|
Field | <div> | Wrapper grouping label, input, description, and error |
FieldLabel | <label> | Semantic label linked to the input via htmlFor |
FieldControl | <div> | The box a control sits in: fill, edge, focus ring, invalid look, glass under data-glass="on" |
FieldDescription | <p> | Helper text providing additional context for the field |
FieldError | <div> | Error message container with role="alert" for live announcements |
Accessibility
Fieldrenders as a<div>— pair withFieldsetfor groups of related fieldsFieldLabelrenders a semantic<label>— always usehtmlFormatching the control'sidFieldDescriptionrenders with a generatedidthat can be referenced byaria-describedbyon the inputFieldErrorrenders withrole="alert"so screen readers announce errors immediately- Set
aria-invalid="true"on the input when showing aFieldErrorto communicate the invalid state; insideFieldControlthe box reads it for the invalid look FieldLabel optionalputs "optional" inside the label, so the control's accessible name includes it- The
FieldErroricon isaria-hidden; the message carries the error - Inside
FieldControl, keyboard focus draws a 2px ring on the box in every look, valid or invalid