Skip to content

Input

input

A 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.

Install

$npxshadcnadd@forme/input

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 error or success and the message and the icon follow.
  • reserveMessage on 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-label from its parent.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

Input

PropTypeDefaultDescription
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.
descriptionReactNode—Help text under the field. Replaced by error, or by a success string.
errorstring—Marks the field invalid: the message is announced and the field shakes once.
successboolean | string—Marks the value accepted and draws a check. A string is shown as the message.
leadingReactNode—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.
trailingReactNode—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.
reserveMessagebooleanfalseHolds 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

  • label is required, and the help text and error share one aria-describedby slot, so only the message that is showing is read.
  • An error sets aria-invalid and is announced with role="alert"; a success message is announced politely.
  • reserveMessage keeps 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.