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.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/formThis 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
└── FormSubmitExamples
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
| Move | What you see |
|---|---|
| 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. |
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.
| Variable | What it changes | Default |
|---|---|---|
--form-face | Submit surface | bg-primary |
--form-ink | Submit label | text-primary-foreground |
--form-muted | Status colour | text-muted-foreground |
--form-radius | Submit corners | rounded-[10px] |
--form-font | Submit size | text-[13px] |
--form-gap | Form section gap | gap-4 |
--form-height | Submit height | h-9 |
--form-inset-x | Submit padding | px-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
| Key | What it does |
|---|---|
| Enter | In a text field, submits the form. Fields are checked first and the first invalid one takes focus. |
| Tab | Moves 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.
More in Forms
All componentsFilter
The faceted filter of a data table's toolbar: a dashed chip that opens a searchable list of values with counts, built on UI SDK's combobox. Chosen values arrive in the chip as badges one after another while the chip widens around them on a spring, counts roll, and a bar of filters slides its Reset in while any is active.
Input
The focus ring closes in around the field on a spring.