Forms
Field
Free3.0 KB gzippedWraps one form control with a label, hint, and error message, and wires them together: <label for>, aria-describedby, aria-invalid, aria-errormessage, required, and disabled all flow to the control through FieldContext.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab · Full report
Import
import {
Field,
FieldLabel,
FieldHint,
FieldError,
FieldProvider,
Fieldset,
} from "@vjdesigns/vjdesigns-ui";
Importing only Field adds about 3.0 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Field adds a label, hint and error to any control inside it and wires up the ARIA for you.
A sentence or two about you.
import { Field, Input, Stack, Textarea } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
return (
<Stack gap={5} style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Full name" required>
<Input autoComplete="name" />
</Field>
<Field label="Bio" hint="A sentence or two about you.">
<Textarea rows={3} />
</Field>
</Stack>
);
}
Validation
Pass error to show a message and mark the control invalid.
Enter an email address like name@example.com.
import { useState } from "react";
import { Field, Input } from "@vjdesigns/vjdesigns-ui";
export function Validation() {
const [email, setEmail] = useState("jordan@");
const error = /^\S+@\S+\.\S+$/.test(email) ? undefined : "Enter an email address like name@example.com.";
return (
<div style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Email" error={error}>
<Input type="email" value={email} onValueChange={setEmail} />
</Field>
</div>
);
}
Horizontal
orientation="horizontal" puts the label beside the control.
Optional
import { Field, Input, Stack } from "@vjdesigns/vjdesigns-ui";
export function Horizontal() {
return (
<Stack gap={4} style={{ width: "100%", maxWidth: "28rem" }}>
<Field label="Username" orientation="horizontal">
<Input defaultValue="jlee" />
</Field>
<Field label="Website" orientation="horizontal" hint="Optional">
<Input startAddon="https://" />
</Field>
</Stack>
);
}
Grouping
Fieldset groups related controls under one legend.
import {
Button,
Field,
Fieldset,
Input,
Radio,
RadioGroup,
Stack,
} from "@vjdesigns/vjdesigns-ui";
export function Grouping() {
return (
<form style={{ width: "100%", maxWidth: "24rem" }} onSubmit={(event) => event.preventDefault()}>
<Stack gap={5}>
<Fieldset label="Shipping address">
<Field label="Street">
<Input autoComplete="street-address" />
</Field>
<Field label="City">
<Input autoComplete="address-level2" />
</Field>
</Fieldset>
<RadioGroup label="Delivery speed" defaultValue="standard">
<Radio value="standard" label="Standard" description="3–5 business days" />
<Radio value="express" label="Express" description="Next business day" />
</RadioGroup>
<Button type="submit">Save address</Button>
</Stack>
</form>
);
}
Accessibility
Errors that appear after submitting should be announced: announceError puts the message in a role="alert" region. Errors shown while typing stay quiet by default, so screen reader users aren't interrupted on every keystroke.
import { useState } from "react";
import { Button, Field, Input, Stack } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const [submitted, setSubmitted] = useState(false);
const [name, setName] = useState("");
const error = submitted && !name.trim() ? "Enter the name on the card." : undefined;
return (
<form
noValidate
style={{ width: "100%", maxWidth: "22rem" }}
onSubmit={(event) => {
event.preventDefault();
setSubmitted(true);
}}
>
<Stack gap={4}>
<Field label="Name on card" required error={error} announceError>
<Input value={name} onValueChange={setName} autoComplete="cc-name" fullWidth />
</Field>
<Button type="submit">Pay now</Button>
</Stack>
</form>
);
}
Translated
Field has no built-in words: the label, hint and error are your text. Inside a LocaleProvider, the fields it wraps get their built-in text and number formats from the locale (Spanish here).
Te enviaremos el recibo aquí.
Escribe al menos 10 caracteres.
import {
Field,
Input,
Stack,
Textarea,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import es from "@vjdesigns/vjdesigns-ui/locales/es";
export function Translated() {
return (
<LocaleProvider locale="es" messages={es}>
<Stack gap={4} style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Correo electrónico" hint="Te enviaremos el recibo aquí." required>
<Input type="email" defaultValue="ana@ejemplo.com" clearable fullWidth />
</Field>
<Field label="Comentarios" error="Escribe al menos 10 caracteres.">
<Textarea defaultValue="Hola" fullWidth />
</Field>
</Stack>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
A sentence or two about you.
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
API reference
Field
| Prop | Type | Default |
|---|---|---|
idid for the control. The label's | string | — |
orientation
| "horizontal""vertical" | — |
labelActionContent at the end of the label row, e.g. a "Forgot password?" link. | ReactNode | — |
counterContent at the end of the hint row, e.g. a character counter "12/280". It is not wired to the control; if it must be announced, give it its own polite live region or mention the limit in | ReactNode | — |
childrenThe control (Input, Select, ...). It reads ids and state with | ReactNode | — |
labelRequiredVisible label (a | ReactNode | — |
labelVisuallyHiddenKeep the label for screen readers but hide it visually (e.g. a search box next to a visible heading). | boolean | — |
hintHelp text, wired to the control with | ReactNode | — |
errorError message. When present the field is invalid (unless | ReactNode | — |
invalidInvalid state. Defaults to | boolean | — |
requiredRequired. Controls set native | boolean | — |
disabledDisabled. Passed to controls through context; | boolean | — |
readOnlyRead-only. Passed to controls through context. | boolean | — |
sizeSize shared with controls that don't set their own. Also scales the label. | "sm""md""lg" | — |
requiredIndicatorVisual marker shown after the label when | ReactNode | — |
optionalIndicatorShow a marker after the label when the field is *not* required. | ReactNode | — |
announceErrorPut the error message in a | boolean | — |
Also accepts native <div> attributes, plus className, style and ref.
FieldLabel
The label of a Field. Reads htmlFor and id from the surrounding Field; use it standalone for custom layouts (pass htmlFor outside a Field).
| Prop | Type | Default |
|---|---|---|
requiredShow | boolean | — |
requiredIndicatorMarker shown when required. Defaults to an | ReactNode | — |
optionalIndicatorMarker shown when not required. | ReactNode | — |
sizeLabel size. Defaults to the surrounding Field's size, then | "sm""md""lg" | — |
Also accepts native <label> attributes, plus className, style and ref.
FieldHint
Help text for a Field. Takes the Field's hint id and registers itself, so controls reference it with aria-describedby. Renders nothing when empty.
Also accepts standard HTML attributes, plus className, style and ref.
FieldError
Error message for a Field, with a leading decorative error icon so the state isn't conveyed by color alone. Takes the Field's error id and registers itself; controls reference it only while the Field is invalid. Renders nothing when empty (except the live region when announce is on).
| Prop | Type | Default |
|---|---|---|
announceWrap the message in a persistent | boolean | — |
Also accepts native <p> attributes, plus className, style and ref.
FieldProvider
Provides FieldContext without rendering any markup, for fully custom layouts built from FieldLabel, FieldHint, and FieldError. The hint and error register themselves, so the control's aria-describedby and aria-errormessage stay correct wherever they are placed.
| Prop | Type | Default |
|---|---|---|
idid for the control. Generated when omitted. | string | — |
invalidInvalid state. Controls set | boolean | — |
requiredRequired. | boolean | — |
disabledDisabled. | boolean | — |
readOnlyRead-only. | boolean | — |
sizeSize shared with controls. | "sm""md""lg" | — |
childrenYour own layout: | ReactNode | — |
Fieldset
Group mode of Field: a <fieldset> with a <legend>, for a set of related controls (RadioGroup, CheckBoxGroup, or native radios and checkboxes). Provides FieldContext with isGroup: true, so group controls label themselves with the legend's id. Native disabled on the fieldset disables every descendant control. The hint sits under the legend (read before the options); the error sits after the controls.
| Prop | Type | Default |
|---|---|---|
requiredTextVisually hidden text added to the legend when | string | — |
childrenThe group of controls (native radios / checkboxes, RadioGroup, CheckBoxGroup). | ReactNode | — |
labelRequiredVisible label (a | ReactNode | — |
labelVisuallyHiddenKeep the label for screen readers but hide it visually (e.g. a search box next to a visible heading). | boolean | — |
hintHelp text, wired to the control with | ReactNode | — |
errorError message. When present the field is invalid (unless | ReactNode | — |
invalidInvalid state. Defaults to | boolean | — |
requiredRequired. Controls set native | boolean | — |
disabledDisabled. Passed to controls through context; | boolean | — |
readOnlyRead-only. Passed to controls through context. | boolean | — |
sizeSize shared with controls that don't set their own. Also scales the label. | "sm""md""lg" | — |
requiredIndicatorVisual marker shown after the label when | ReactNode | — |
optionalIndicatorShow a marker after the label when the field is *not* required. | ReactNode | — |
announceErrorPut the error message in a | boolean | — |
Also accepts native <fieldset> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Field targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves to the control inside; the field adds no keys of its own. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Label | none | Names the control (<label for> or aria-labelledby) |
| Control | Its own | aria-describedby → hint and error, aria-invalid, aria-errormessage, aria-required |
| Error | alert | Announced when it appears |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |