Field

A label, control, help text and error, wired and validated.

Source
$npx @dinachi/cli@latest add field

We'll never share your email.

invalid
disabled
FieldDescription

Usage

import {
  Field,
  FieldControl,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@/components/ui/field"

export function EmailField() {
  return (
    <Field name="email">
      <FieldLabel>Email</FieldLabel>
      <FieldControl type="email" required />
      <FieldDescription>We only use it to sign you in.</FieldDescription>
      <FieldError />
    </Field>
  )
}

Examples

We'll never share your email.

Label, control and description.
import { Field, FieldLabel, FieldControl, FieldDescription } from '@/components/ui/field';

export function Example() {
  return (
    <Field className="w-full max-w-sm">
      <FieldLabel>Email</FieldLabel>
      <FieldControl type="email" placeholder="Enter your email" />
      <FieldDescription>We'll never share your email.</FieldDescription>
    </Field>
  );
}

Notes

Required fields

Put required on FieldControl. It shows nothing visually; mark the label too.

Server errors

Inside a Form, pass errors keyed by each Field's name. Each error clears once its control changes.

API

namestring
Names the field on submit and keys its server errors.
validate(value, formValues) => string | string[] | null
Returns an error message, or nothing when valid. May be async.
validationMode"onSubmit" | "onBlur" | "onChange" = "onSubmit"
When validate runs. Wins over the Form's setting.
validationDebounceTimenumber = 0
Milliseconds between validate calls in onChange mode.
invalid
agent
boolean
Marks the field invalid, for example from a form library.
disabled
agent
boolean = false
Disables the control. Overrides the control's own disabled.

Accessibility

  • FieldLabel labels the control; clicking it focuses the input.
  • FieldDescription and FieldError describe the control via aria-describedby.
  • Invalid controls get aria-invalid and data-invalid.
  • While invalid, the agent reads FieldError's text as the control's errors.