Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

Field

Free3.0 KB gzipped

Wraps 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

tsx
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.

tsx
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.

tsx
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.

https://

Optional

tsx
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.

Shipping address
Delivery speed
tsx
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.

tsx
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.

tsx
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.

tsx
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

Field props
PropTypeDefault
id

id for the control. The label's htmlFor points here, and controls read it from context. Generated with useId when omitted. (The wrapper div gets no id.)

string—
orientation

vertical (default): label above the control. horizontal: label to the left, falling back to vertical when the Field is narrower than 30rem (a container query, so it adapts to its column, not the viewport).

"horizontal""vertical"—
labelAction

Content at the end of the label row, e.g. a "Forgot password?" link.

ReactNode—
counter

Content 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 hint.

ReactNode—
children

The control (Input, Select, ...). It reads ids and state with useFieldControl.

ReactNode—
labelRequired

Visible label (a <legend> in Fieldset). Always required so every control has an accessible name; use labelVisuallyHidden when the design has no visible label.

ReactNode—
labelVisuallyHidden

Keep the label for screen readers but hide it visually (e.g. a search box next to a visible heading).

boolean—
hint

Help text, wired to the control with aria-describedby.

ReactNode—
error

Error message. When present the field is invalid (unless invalid={false}), and the message is wired with aria-describedby and aria-errormessage. It renders with a leading error icon so the state isn't conveyed by color alone. With invalid={false} the message is not rendered.

ReactNode—
invalid

Invalid state. Defaults to true when error is present, otherwise false.

boolean—
required

Required. Controls set native required (or aria-required for custom controls), which is what assistive tech announces; the label shows requiredIndicator.

boolean—
disabled

Disabled. Passed to controls through context; Fieldset also sets native disabled, which disables every descendant control.

boolean—
readOnly

Read-only. Passed to controls through context.

boolean—
size

Size shared with controls that don't set their own. Also scales the label.

"sm""md""lg"—
requiredIndicator

Visual marker shown after the label when required. Defaults to a * that is aria-hidden (the control's native required carries the meaning for assistive tech). Pass false or null to hide it, or any node to customize.

ReactNode—
optionalIndicator

Show a marker after the label when the field is *not* required. true shows "(optional)"; pass a node to customize or localize it. Off by default. Use it in forms where most fields are required.

ReactNode—
announceError

Put the error message in a role="alert" live region, so it is announced when it appears. Off by default: announcing every inline validation message is noisy. Turn it on for errors that appear after submit or an async check. The live region stays mounted while announceError is on, so the message is announced reliably when it is added.

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).

FieldLabel props
PropTypeDefault
required

Show requiredIndicator or optionalIndicator. Defaults to the surrounding Field's required.

boolean—
requiredIndicator

Marker shown when required. Defaults to an aria-hidden *. false or null hides it.

ReactNode—
optionalIndicator

Marker shown when not required. true shows "(optional)". Off by default.

ReactNode—
size

Label size. Defaults to the surrounding Field's size, then md.

"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).

FieldError props
PropTypeDefault
announce

Wrap the message in a persistent role="alert" live region so it is announced when it appears. Off by default (see Field's announceError).

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.

FieldProvider props
PropTypeDefault
id

id for the control. Generated when omitted.

string—
invalid

Invalid state. Controls set aria-invalid and reference a mounted FieldError.

boolean—
required

Required.

boolean—
disabled

Disabled.

boolean—
readOnly

Read-only.

boolean—
size

Size shared with controls.

"sm""md""lg"—
children

Your own layout: FieldLabel, the control, FieldHint, FieldError, anywhere inside.

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.

Fieldset props
PropTypeDefault
requiredText

Visually hidden text added to the legend when required, because a group has no native required that screen readers announce for the legend. Localize it here.

string—
children

The group of controls (native radios / checkboxes, RadioGroup, CheckBoxGroup).

ReactNode—
labelRequired

Visible label (a <legend> in Fieldset). Always required so every control has an accessible name; use labelVisuallyHidden when the design has no visible label.

ReactNode—
labelVisuallyHidden

Keep the label for screen readers but hide it visually (e.g. a search box next to a visible heading).

boolean—
hint

Help text, wired to the control with aria-describedby.

ReactNode—
error

Error message. When present the field is invalid (unless invalid={false}), and the message is wired with aria-describedby and aria-errormessage. It renders with a leading error icon so the state isn't conveyed by color alone. With invalid={false} the message is not rendered.

ReactNode—
invalid

Invalid state. Defaults to true when error is present, otherwise false.

boolean—
required

Required. Controls set native required (or aria-required for custom controls), which is what assistive tech announces; the label shows requiredIndicator.

boolean—
disabled

Disabled. Passed to controls through context; Fieldset also sets native disabled, which disables every descendant control.

boolean—
readOnly

Read-only. Passed to controls through context.

boolean—
size

Size shared with controls that don't set their own. Also scales the label.

"sm""md""lg"—
requiredIndicator

Visual marker shown after the label when required. Defaults to a * that is aria-hidden (the control's native required carries the meaning for assistive tech). Pass false or null to hide it, or any node to customize.

ReactNode—
optionalIndicator

Show a marker after the label when the field is *not* required. true shows "(optional)"; pass a node to customize or localize it. Off by default. Use it in forms where most fields are required.

ReactNode—
announceError

Put the error message in a role="alert" live region, so it is announced when it appears. Off by default: announcing every inline validation message is noisy. Turn it on for errors that appear after submit or an async check. The live region stays mounted while announceError is on, so the message is announced reliably when it is added.

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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

37 passed · 0 failed · 28 not applicable · 10 to check by hand

Dark mode

Score 100

37 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

Keyboard
KeyAction
TabMoves to the control inside; the field adds no keys of its own.

Roles and states

Roles and states
ElementRoleStates and properties
LabelnoneNames the control (<label for> or aria-labelledby)
ControlIts ownaria-describedby → hint and error, aria-invalid, aria-errormessage, aria-required
ErroralertAnnounced when it appears

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)