Field
Labels, hints and errors move together: an error slides in under the field and the ring turns red.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/fieldThis adds components/keyframery/field.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/keyframery/field"
import { Input } from "@/components/keyframery/input"
export default function Usage() {
return (
<Field name="email">
<FieldLabel>Email</FieldLabel>
<Input type="email" required />
<FieldDescription>We never share it.</FieldDescription>
<FieldError match="valueMissing">Enter your email.</FieldError>
</Field>
)
}Anatomy
How the parts fit together:
Field
├── FieldLabel
├── FieldDescription
└── FieldErrorExamples
Validation
FieldError shows the message that matches the browser's own check, once the field has been left or the form sent.
A set of fields
FieldSet and FieldLegend group related fields, and FieldGroup spaces them. Disabling the set disables every field in it.
Server errors
Pass invalid to show an error you got back from the server. FieldError without match always shows while the field is invalid.
Motion
| Move | What you see |
|---|---|
| Height | An error message opens the space it needs and rises in. |
| Direction | Hint and error swap places instead of jumping. |
| Fade | The ring and label turn red together. |
Timing and springiness follow the motion style you set. To change how fast this field moves, pass speed:
<Field speed="fast">
…
</Field>"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 |
|---|---|---|
--field-height | Native control height | 2.25rem |
--field-radius | Native control corners | 10px |
--field-face | Native control surface | --background |
--field-ink | Labels, legends and native control text | --foreground |
--field-muted | Descriptions and placeholders | --muted-foreground, placeholders 70% |
--field-error | Errors and invalid control hairline | --destructive |
--field-gap | Label, control and message spacing | 0.375rem |
API reference
Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK field reference.
Field
Renders a <div>, and takes its props too.
Prop
Type
FieldError
Renders a <div>, and takes its props too.
Prop
Type
FieldSet
Renders a <fieldset>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
FieldLabel: a<label>FieldDescription: a<p>FieldControl: a<input>FieldGroup: a<div>FieldLegend: a<legend>
Hooks
useFieldControl
Connects a control of your own to the field it sits in, so the label, description and error message point at it.
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.
Swap the import
Already using UI SDK's field with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/field"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/field"Questions
How does the animated Field for UI SDK move?
Height: An error message opens the space it needs and rises in. Direction: Hint and error swap places instead of jumping. Fade: The ring and label turn red together.
Do I need Motion or Framer Motion for the animated Field?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/field instead. It has the same parts and props as @ui-sdk/react/field and adds motion only.
What happens to the Field when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.