Input
inputA text field with a real label, optional description, an error that is announced and wired up with aria-describedby, a success state that draws its own check, and room for an icon or a button on either side. Invalid and accepted states arrive with motion; sizes come from the same tokens as every other Forme surface.
"use client";
import { Eye, EyeOff, Lock, Mail, Search } from "lucide-react";
import { useState } from "react";
import { Input } from "@/components/forme/input/input";
export function InputDemo() {
const [visible, setVisible] = useState(false);
const [email, setEmail] = useState("");
const [handle, setHandle] = useState("ada");
// Validated as it is typed, not on submit: an address that is wrong halfway
// through is still wrong, and the message says what to do about it.
const emailError =
email.length > 0 && !email.includes("@")
? "Enter an address, like you@company.com."
: undefined;
return (
<div className="flex flex-col gap-8">
<div className="grid max-w-sm gap-4">
<Input
label="Email"
type="email"
placeholder="you@company.com"
leading={<Mail />}
value={email}
onChange={(event) => setEmail(event.target.value)}
error={emailError}
reserveMessage
/>
<Input
label="Workspace"
description="Lowercase letters, digits and dashes."
value={handle}
onChange={(event) => setHandle(event.target.value)}
success={handle.length >= 3 && /^[a-z0-9-]+$/.test(handle)}
reserveMessage
/>
</div>
<div className="grid max-w-sm gap-4">
<Input
label="Search components"
placeholder="button, card, tabs"
leading={<Search />}
trailing={
<kbd className="rounded border border-border bg-muted px-1.5 py-0.5 font-mono text-caption-2-regular text-muted-foreground">
⌘K
</kbd>
}
/>
<Input
label="Password"
type={visible ? "text" : "password"}
leading={<Lock />}
defaultValue="hunter2"
trailing={
<button
type="button"
onClick={() => setVisible((shown) => !shown)}
aria-label="Show password"
aria-pressed={visible}
>
{visible ? <EyeOff /> : <Eye />}
</button>
}
/>
</div>
<div className="grid max-w-sm gap-4">
<Input
label="Email"
error="Enter an email address, like you@company.com."
defaultValue="ada@"
/>
<Input label="Email" error="That address is already in use." />
</div>
<div className="flex flex-wrap items-end gap-4">
<Input label="Medium" className="w-40" defaultValue="acme" />
<Input label="Large" size="lg" className="w-40" defaultValue="acme" />
<Input label="Disabled" className="w-40" disabled defaultValue="acme" />
<Input label="Read only" className="w-40" readOnly defaultValue="acme" />
</div>
</div>
);
}Install
Adds the component, its registry dependencies, and the token stylesheet you import once.
Usage
import { Input } from "@/components/forme/input/input";
<Input label="Email" type="email" description="We send the receipt here." />When to use
Reach for it
- A single line of text, with its label, its help text and its error in one component.
- A field whose validity is known as it is typed: pass
errororsuccessand the message and the icon follow. reserveMessageon a form that validates on submit, so the error does not push the button down when it appears.
Use something else
- Several lines of text; use a
Textarea. - A one-time code split into boxes; that is the
OtpInput. - A field with no visible label; the search box in a toolbar is the one exception, and it takes
aria-labelfrom its parent.
API reference
Read from the source, so it is the API of the file you install. A prop marked * is required.
Input
| Prop | Type | Default | Description |
|---|---|---|---|
label* | string | — | Visible label. Required rather than optional: an unlabelled field is a mystery to anyone using a screen reader, and a placeholder is not a label. |
description | ReactNode | — | Help text under the field. Replaced by error, or by a success string. |
error | string | — | Marks the field invalid: the message is announced and the field shakes once. |
success | boolean | string | — | Marks the value accepted and draws a check. A string is shown as the message. |
leading | ReactNode | — | Sits inside the field before the text. Decorative and unclickable, so it is hidden from assistive technology; use trailing for anything a person has to reach. |
trailing | ReactNode | — | Sits inside the field after the text. Buttons are allowed, and get a target the height of the field less its padding rather than whatever size their icon happens to be. |
reserveMessage | boolean | false | Holds one message line when there is no message, so an error arriving on submit moves nothing below the field. The reveal then fades rather than growing, because the space is already there. |
size | 'md' | 'lg' | "md" |
Also takes every prop of <input> attributes.
Accessibility
labelis required, and the help text and error share onearia-describedbyslot, so only the message that is showing is read.- An
errorsetsaria-invalidand is announced withrole="alert"; a success message is announced politely. reserveMessagekeeps the space but not the text: an empty live region is not announced.
Motion
- The field shakes once when a new error arrives, and never on mount, so a server-rendered error does not flinch at paint.
- The message opens its own height on a spring when the line is not reserved, and only fades when it is.
- The success check condenses in from slightly under size and draws itself; reduced motion keeps the fade and drops the movement.
Related


Calendar
A month grid for a single date or a range, with no date library. Full WAI-ARIA keyboard support, month and year pickers, min, max and disabled days, a range that previews under the pointer or the keyboard, and a fixed six-week height so nothing below it jumps.
inputsColor picker
A full colour editor: a saturation and brightness area, hue and opacity rails, a hex field, numeric channels, screen sampling and preset swatches — all composed from parts, opened from a trigger chip that previews the value.
inputsColor selector
A row of colour swatches where exactly one is chosen. Real radio inputs inside a fieldset, so forms, required state, arrow keys and screen-reader grouping all work natively, and one selection ring hops between swatches.
inputs