When to use
- Any labelled form control that can carry help text or an error: an email address, a password, a verification code.
- Forms validated on the client with
validate, by the browser (required,type="email"), or by the server through Base UI's<Form errors>. - Wrapping Eased's text controls (Input, Textarea, OTP Field) so their invalid border and shake follow the field.
When not to use
Installation
pnpm dlx shadcn add https://eased.dev/r/field.jsonnpx shadcn add https://eased.dev/r/field.jsonyarn dlx shadcn add https://eased.dev/r/field.jsonbunx --bun shadcn add https://eased.dev/r/field.jsonThe command adds Field, everything it builds on and Eased’s tokens to your project.
Add the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/field/field.tsxTSX "use client";import type { ReactNode } from "react";import { FieldLabel, FieldMessage, FieldRoot, type FieldRootProps,} from "../_primitives/field/field";export type FieldProps = Omit<FieldRootProps, "children"> & { /** The visible label, tied to the control for you. */ label?: ReactNode; /** Helper text under the control. While the field is invalid the error takes its place. */ description?: ReactNode; /** * An error you control (a server reply, a form library). Setting it marks the field invalid. * Leave it out to show the message from `validate`, `<Form errors>` or the browser. */ error?: ReactNode; /** One control: `<Input>`, `<Textarea>`, `<SearchField>`, or any Base UI control. */ children: ReactNode;};/** * Label, control and one message line, on Base UI's Field. The description and the error * share the line and swap with y + blur; the line's height springs when it opens or rewraps. * Inside Base UI's `<Form>`, submitting focuses the first invalid field. */export function Field({ label, description, error, invalid, children, ...props }: FieldProps) { const hasError = error !== undefined && error !== null && error !== false && error !== ""; return ( <FieldRoot {...props} invalid={invalid ?? (hasError || undefined)}> {label !== undefined && <FieldLabel>{label}</FieldLabel>} {children} <FieldMessage description={description} error={hasError ? error : undefined} /> </FieldRoot> );}export { FieldRoot, FieldLabel, FieldMessage } from "../_primitives/field/field";Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Form } from "@base-ui/react/form";import { Field } from "@/components/eased/field/field";import { Input } from "@/components/eased/input/input";const checkEmail = (value: unknown) => /@(gmail|yahoo|hotmail)\./i.test(String(value)) ? "Use your work email, not a personal one." : null;export function SignUp({ serverErrors, submit }) { return ( <Form errors={serverErrors} onFormSubmit={submit}> <Field name="email" label="Work email" description="We’ll send a sign-in link." validate={checkEmail}> <Input type="email" autoComplete="email" /> </Field> </Form> );}Examples
An error you control
Pass error when the message comes from somewhere else, such as a form library or a server reply. Setting it marks the field invalid; clear it when the person edits.
<Field label="Workspace URL" error={taken ? "That URL is already in use." : undefined}> <Input value={slug} onChange={(e) => setSlug(e.target.value)} /></Field>Validate on blur
Base UI validates on submit by default, then again on every change. Set validationMode to check earlier.
<Field name="password" label="Password" description="At least 8 characters." validationMode="onBlur" validate={checkPassword}> <Input type="password" autoComplete="new-password" /></Field>API reference
Field
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | The visible label, tied to the control for you. | |
description | ReactNode | Helper text under the control. While the field is invalid the error takes its place. | |
error | ReactNode | An error you control. Setting it marks the field invalid. Leave it out to show the message from validate, <Form errors> or the browser. | |
invalid | boolean | Marks the field invalid; overrides the state error sets. | |
children | ReactNode | One control: Input, Textarea, OTP Field or any Base UI control. |
Every other Base UI Field.Root prop passes through: name, validate, validationMode, validationDebounceTime, disabled, dirty, touched, actionsRef, className, render.
FieldRoot, FieldLabel and FieldMessage
The parts Field is made of, exported for custom layouts. FieldRoot is Base UI's Field.Root with a 6px rhythm between its parts. FieldLabel is Field.Label. FieldMessage takes description, error and className, and must sit inside a FieldRoot.
Accessibility
- Base UI ties the label to the control and points
aria-describedbyat the description and error. - The message line sits in a polite live region, so a new error is announced without moving focus.
- Inside Base UI's
<Form>, submitting with errors moves focus to the first invalid control. - Errors carry an icon and the danger colour as well as the shake, so motion is never the only signal.
Motion
The description and the error share one line and swap in place: the outgoing line lifts 3px and blurs out in 100ms, the incoming one rises from 4px below on the snappy spring while its blur and opacity clear over 200ms. When the line count changes, or an error opens the line from nothing, its height springs on the smooth spring; in that last case it waits 80ms so the control's 6px shake lands first. A new message replaces an old one the same way. Reduced motion swaps by opacity alone in 100ms and snaps the height.
Notes for AI
Wrap every labelled text control in a Field and pass label and description here rather than on the control. Use validate or Base UI's <Form errors> for messages, and error only when the message comes from outside Base UI.
Do not render your own error paragraph, aria-describedby or aria-live region, and do not add a second label: the Field already wires them. Keep one control per Field.
Related components
- Animated Text Input: the text control it usually wraps.
- Auto-Resizing Textarea: for longer text.
- Label: a standalone label when you do not need the message line.