Form Field

A composable form field that wires a Label, control, helper text, and error message together via React context. The useFormField hook provides the field ID and error state to any child component.

We'll send a confirmation to this address.

import { FormField, FormLabel, FormControl, FormDescription, FormMessage }from "@aetherstack/patterns"

Installation

terminal
npx aether-ui add form-field

Usage

form-field-usage.tsx
import {
  FormField,
  FormLabel,
  FormControl,
  FormDescription,
  FormMessage,
} from "@aetherstack/patterns"
import { Input } from "@aetherstack/ui"

// Basic field
<FormField name="email" required>
  <FormLabel>Email address</FormLabel>
  <FormControl>
    <Input type="email" placeholder="you@example.com" />
  </FormControl>
  <FormDescription>We'll send a confirmation to this address.</FormDescription>
</FormField>

// Field with error
<FormField name="email" error="Invalid email address">
  <FormLabel>Email address</FormLabel>
  <FormControl>
    <Input type="email" />
  </FormControl>
  <FormMessage />
</FormField>

Props

ComponentPropTypeDescription
FormFieldnamestringUsed to generate stable IDs for label/input association.
FormFieldidstringExplicit ID override. Auto-generated from name if omitted.
FormFielderrorstringError message. When set, label turns red and FormMessage shows it.
FormFieldrequiredbooleanAdds a red asterisk to the label.
FormLabelLabelPropsForwards all Label props. htmlFor is set automatically.
FormControlchildrenReactElementSingle child element that receives the id and aria-describedby.
FormDescriptionHTMLParagraphElement propsHelper text below the control.
FormMessagechildrenReactNodeShown when FormField has an error. Falls back to children.

Accessibility

  • FormLabel sets htmlFor to the field ID automatically — no manual wiring needed.
  • FormControl adds aria-describedby pointing to the description and/or error message.
  • FormControl adds aria-invalid="true" when an error is present.
  • FormMessage renders with role="alert" to announce errors to screen readers.
  • Required fields show a visual asterisk (aria-hidden) — combine with required on the native input for full a11y.