Keyframery

Form

Fields that settle back while the form sends, a submit button whose label rises through sending to a drawn check, and server errors that open in place under the field they belong to.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/form

This adds components/keyframery/form.tsx and its primitive to your project, and installs UI SDK, along with field, which it builds on. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Form, FormItem, FormLabel, FormMessage, FormSubmit } from "@/components/keyframery/form"
import { Input } from "@/components/keyframery/input"

export default function Usage() {
  return (
    <Form submit={async (data) => console.log(data.get("email"))}>
      <FormItem name="email">
        <FormLabel>Email</FormLabel>
        <Input type="email" required />
        <FormMessage />
      </FormItem>
      <FormSubmit>Subscribe</FormSubmit>
    </Form>
  )
}

Anatomy

How the parts fit together:

Form
├── FormItem
│   ├── FormLabel
│   └── FormMessage
└── FormSubmit

Examples

Errors from your server

Return { errors: { name: message } } from submit and each message shows on its field, in the same place and the same way as the browser's own validation. Editing the field clears it.

Following the submission

onStatusChange reports submitting, success and error with a reason. A rejected submit shows its message in FormStatus, read out as an alert.

Motion

MoveWhat you see
HeightAn error, from the browser or from your server, opens its own height under its field and rises in out of a blur.
DirectionThe submit button's label rises out to the pending label with a spinner, then to the success label; refused, it comes back down.
DrawThe check in the success label strokes itself in.
FadeWhile the form sends, its fields settle back a little and come forward again when it is done.
PressThe submit button sinks and springs back.

Timing and springiness follow the motion style you set. To change how fast this form moves, pass speed:

<Form speed="fast">
  …
</Form>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--form-faceSubmit surfacebg-primary
--form-inkSubmit labeltext-primary-foreground
--form-mutedStatus colourtext-muted-foreground
--form-radiusSubmit cornersrounded-[10px]
--form-fontSubmit sizetext-[13px]
--form-gapForm section gapgap-4
--form-heightSubmit heighth-9
--form-inset-xSubmit paddingpx-4

API reference

Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.

Form

Renders a <form>, and takes its props too.

Prop

Type

FormItem

Renders a <div>, and takes its props too.

Prop

Type

FormMessage

Renders a <div>, and takes its props too.

Prop

Type

FormSubmit

Renders a <button>, and takes its props too.

Prop

Type

FormField

Renders a <div>, and takes its props too.

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • FormLabel: a <label>
  • FormControl: a <input>
  • FormDescription: a <p>
  • FormStatus: a <p>

Hooks

useFieldControl

Connects a control of your own to the field it sits in, so the label, description and error message point at it.

Keyboard

KeyWhat it does
EnterIn a text field, submits the form. Fields are checked first and the first invalid one takes focus.
TabMoves between the fields and the submit button.

Accessibility

Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.

Built on UI SDK's core

UI SDK doesn't ship a form, so this one is defined with its core: one definePrimitive in components/keyframery/core/form-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/form.

Questions

How does the animated Form for UI SDK move?

Height: An error, from the browser or from your server, opens its own height under its field and rises in out of a blur. Direction: The submit button's label rises out to the pending label with a spinner, then to the success label; refused, it comes back down. Draw: The check in the success label strokes itself in. Fade: While the form sends, its fields settle back a little and come forward again when it is done. Press: The submit button sinks and springs back.

Do I need Motion or Framer Motion for the animated Form?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

UI SDK has no form. How is this one built on UI SDK?

Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/form-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.

What happens to the Form when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page