Field
Accessible form fields and validation with height-animated error alerts, crossfading descriptions, text-drift error copy, staggered error shakes, plus floating-label and character-count input effects.
Customize
Installation
Add the base field and form primitives:
npx shadcn@latest add @kinetic/fieldAdd optional input effects independently when needed:
npx shadcn@latest add @kinetic/floating-label-input
npx shadcn@latest add @kinetic/char-count-inputUsage
Wrap a control with Field and FieldControl to automatically wire id, aria-invalid, and aria-describedby. Place FieldDescription and FieldError inside FieldMessage so error states open height with useAnimatedSize and crossfade in one grid cell without layout jumps.
"use client";
import { useState } from "react";
import {
Field,
FieldControl,
FieldDescription,
FieldError,
FieldLabel,
FieldMessage,
Form,
} from "@/components/kinetic/ui/field";
import { Input } from "@/components/kinetic/ui/input";
interface AccountFormProps {
readonly onValidSubmit: (email: string) => void;
}
export function AccountForm({ onValidSubmit }: AccountFormProps) {
const [email, setEmail] = useState("");
const [error, setError] = useState<string | undefined>();
return (
<Form
onValidate={() => {
const nextError = email.includes("@") ? undefined : "Enter a valid email.";
setError(nextError);
return nextError ? { email: nextError } : undefined;
}}
onSubmit={(event) => {
if (!event.defaultPrevented && email.includes("@")) {
onValidSubmit(email);
}
}}
>
<Field name="email" invalid={Boolean(error)}>
<FieldLabel>Email</FieldLabel>
<FieldControl>
<Input value={email} onValueChange={setEmail} placeholder="alex@example.com" />
</FieldControl>
<FieldMessage>
<FieldDescription>Notifications and changelog digest only.</FieldDescription>
<FieldError>{error}</FieldError>
</FieldMessage>
</Field>
</Form>
);
}Field separator
Use FieldSeparator inside FieldGroup to divide form sections with Kinetic Separator line motion. Omit children for a single hairline rule, or pass a label to render symmetric lines around centered text.
import { Field, FieldGroup, FieldLabel, FieldSeparator } from "@/components/kinetic/ui/field";
import { Input } from "@/components/kinetic/ui/input";
<FieldGroup>
<Field>
<FieldLabel>Contact email</FieldLabel>
<Input placeholder="alex@example.com" />
</Field>
<FieldSeparator>Public profile</FieldSeparator>
<Field>
<FieldLabel>Display name</FieldLabel>
<Input placeholder="Alex" />
</Field>
</FieldGroup>Floating label input
Use FloatingLabelInput from @kinetic/floating-label-input inside Field so the label lifts with a snappy spring on focus or non-empty input.
import { Field, FieldError, FieldMessage } from "@/components/kinetic/ui/field";
import { FloatingLabelInput } from "@/components/kinetic/ui/floating-label-input";
interface FloatingNameFieldProps {
readonly value: string;
readonly error?: string;
readonly onValueChange: (next: string) => void;
}
export function FloatingNameField({ value, error, onValueChange }: FloatingNameFieldProps) {
return (
<Field name="fullName" invalid={Boolean(error)}>
<FloatingLabelInput label="Full name" value={value} onValueChange={onValueChange} />
<FieldMessage>
<FieldError>{error}</FieldError>
</FieldMessage>
</Field>
);
}Character count input
Use CharCountInput or CharCountTextarea from @kinetic/char-count-input to display a live sliding-digit counter built on RollingDigits that turns destructive when exceeding maxChars.
import { CharCountTextarea } from "@/components/kinetic/ui/char-count-input";
interface BioCounterFieldProps {
readonly bio: string;
readonly onChange: (next: string) => void;
}
export function BioCounterField({ bio, onChange }: BioCounterFieldProps) {
return (
<CharCountTextarea
value={bio}
onChange={(event) => onChange(event.target.value)}
maxChars={120}
placeholder="Tell teammates what you build..."
/>
);
}API Reference
Field
Provides shared ids, aria-invalid, aria-describedby, and invalid-transition shake coordination.
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | - | Optional field key matching Form.errors or onValidate keys. |
invalid | boolean | false | Marks the field invalid, sets aria-invalid, and triggers a shake on false to true. |
orientation | "vertical" | "horizontal" | "responsive" | "vertical" | Field alignment direction. |
speed | number | 1 | Animation speed multiplier (0.25-4). |
Form
Handles validation on submit, focuses and scrolls to the first invalid control, and runs sequential shakes.
| Prop | Type | Default | Description |
|---|---|---|---|
onValidate | (form: HTMLFormElement) => Record<string, string> | string[] | boolean | void | - | Synchronous validation callback evaluated on submit. |
shakeStaggerMs | number | 55 | Delay step in milliseconds between consecutive invalid field shakes. |
scrollOnError | boolean | true | Scrolls the first invalid control smoothly to center on failed submit. |
FloatingLabelInput
Separate registry effect (@kinetic/floating-label-input) animating a label up on focus or non-empty value.
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | - | Floating label text synced via htmlFor and Field context. |
speed | number | 1 | Spring speed multiplier (0.25-4). |
FieldSeparator
Section divider built on Kinetic Separator supporting either a full-width rule or dual symmetric lines around an inline label.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Optional centered label flanked symmetrically by two drawing Separator lines. |
drawOnView / once / durationMs / speed | boolean / boolean / number / number | - | Drawing viewport trigger, single-run flag, line draw duration, and speed multiplier forwarded to Separator. |
CharCountInput / CharCountTextarea
Separate registry effect (@kinetic/char-count-input) pairing live RollingDigits counters with destructive warning past maxChars.
| Prop | Type | Default | Description |
|---|---|---|---|
maxChars | number | 80 | Target maximum character threshold before switching to destructive state. |
enforceMaxLength | boolean | false | Forwards HTML maxLength attribute to block input past maxChars. |