Skip to main content

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.

Used for release announcements only.

Public profile

Leave short and click Validate to see scroll, focus, and stagger shake.

Maximum 60 characters for author card.

Customize

Shake stagger (ms)55
Speed1

Installation

Add the base field and form primitives:

npx shadcn@latest add @kinetic/field

Add optional input effects independently when needed:

npx shadcn@latest add @kinetic/floating-label-input
npx shadcn@latest add @kinetic/char-count-input

Usage

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.

PropTypeDefaultDescription
namestring-Optional field key matching Form.errors or onValidate keys.
invalidbooleanfalseMarks the field invalid, sets aria-invalid, and triggers a shake on false to true.
orientation"vertical" | "horizontal" | "responsive""vertical"Field alignment direction.
speednumber1Animation speed multiplier (0.25-4).

Form

Handles validation on submit, focuses and scrolls to the first invalid control, and runs sequential shakes.

PropTypeDefaultDescription
onValidate(form: HTMLFormElement) => Record<string, string> | string[] | boolean | void-Synchronous validation callback evaluated on submit.
shakeStaggerMsnumber55Delay step in milliseconds between consecutive invalid field shakes.
scrollOnErrorbooleantrueScrolls 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.

PropTypeDefaultDescription
labelstring-Floating label text synced via htmlFor and Field context.
speednumber1Spring 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.

PropTypeDefaultDescription
childrenReact.ReactNode-Optional centered label flanked symmetrically by two drawing Separator lines.
drawOnView / once / durationMs / speedboolean / 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.

PropTypeDefaultDescription
maxCharsnumber80Target maximum character threshold before switching to destructive state.
enforceMaxLengthbooleanfalseForwards HTML maxLength attribute to block input past maxChars.

Notes

Place FieldDescription and FieldError inside FieldMessage so crossfading between helper copy and errors holds its grid height steady.