Form Field
Form field wrapper with label and error
UI PrimitiveForm Inputs
Overview
A compound component that generates a unique ID and automatically wires htmlFor, aria-invalid, and aria-describedby to its child control. Eliminates manual ID management for form fields.
Usage
import { FormField, Input } from "@leanicon/web-builder-library";
<FormField error={errors.email} required>
<FormField.Label>Email address</FormField.Label>
<FormField.Control>
<Input type="email" placeholder="[email protected]" />
</FormField.Control>
<FormField.Description>We'll never share your email.</FormField.Description>
<FormField.Error />
</FormField>;We'll never share your email.
With error
Please enter a valid email address
Notes
FormField.ControlusesReact.cloneElementto injectid,aria-invalid, andaria-describedbyinto the direct child element.FormField.Descriptionhides itself whenerroris set;FormField.Errorshows itself only whenerroris set.FormField.Errorrenders theerrorprop as text if no children are provided.- Dark mode is handled via semantic tokens.
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
error | string | — | No | |
required | boolean | — | No | |
asChild | boolean | — | No |