Forms
Input
Text field, 40px tall. Focus swaps the border to accent and adds a 3px ring.
react-aria-components
With label
We’ll send a verification link.
"use client";
import { Input } from "@/components/ui/input";
export default function Example() {
return <Input label="Work email" placeholder="you@company.com" description="We’ll send a verification link." className="w-full max-w-80" />;
}Search field
Optional 16px leading icon and trailing content.
⌘K
"use client";
import { Search } from "lucide-react";
import { Input } from "@/components/ui/input";
import { Kbd } from "@/components/ui/kbd";
export default function Example() {
return <Input aria-label="Search" placeholder="Search prospects" icon={<Search />} trailing={<Kbd>⌘K</Kbd>} className="w-full max-w-80" />;
}States
Enter a valid email.
"use client";
import { Input } from "@/components/ui/input";
export default function Example() {
return (
<div className="grid w-full max-w-2xl gap-4 sm:grid-cols-3">
<Input label="Default" placeholder="Work email" />
<Input label="Error" defaultValue="jordan@" errorMessage="Enter a valid email." />
<Input label="Disabled" placeholder="Work email" isDisabled />
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-componentsCreate a
input.tsxfile and paste the following code into it.src/components/ui/input.tsx"use client"; import type { ReactNode } from "react"; import { Group, Input as AriaInput, TextField, type TextFieldProps, } from "react-aria-components"; import { cx } from "@/utils/cx"; import { Description, ErrorMessage, Label, fieldBase } from "./field"; export interface InputProps extends Omit<TextFieldProps, "className" | "children"> { label?: string; description?: string; errorMessage?: string; placeholder?: string; /** 16px icon rendered inside the field, before the text. */ icon?: ReactNode; /** Content rendered at the end of the field, e.g. a <Kbd>. */ trailing?: ReactNode; className?: string; inputClassName?: string; } export function Input({ label, description, errorMessage, placeholder, icon, trailing, className, inputClassName, ...props }: InputProps) { const hasAdornment = Boolean(icon || trailing); return ( <TextField {...props} isInvalid={props.isInvalid ?? Boolean(errorMessage)} className={cx("flex flex-col gap-2", className)} > {label && <Label>{label}</Label>} {hasAdornment ? ( <Group className={cx(fieldBase, "flex h-10 items-center gap-2 px-3 [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-fg-muted")}> {icon} <AriaInput placeholder={placeholder} className={cx("h-full min-w-0 flex-1 bg-transparent outline-none placeholder:text-fg-muted", inputClassName)} /> {trailing} </Group> ) : ( <AriaInput placeholder={placeholder} className={cx(fieldBase, "h-10 px-3", inputClassName)} /> )} {description && !errorMessage && <Description>{description}</Description>} <ErrorMessage>{errorMessage}</ErrorMessage> </TextField> ); }Create a
field.tsxfile and paste the following code into it.src/components/ui/field.tsx"use client"; import type { ReactNode } from "react"; import { FieldError, Label as AriaLabel, Text } from "react-aria-components"; import { cx } from "@/utils/cx"; /** Shared field chrome: 40px tall, radius 12, 1px border-strong, accent border + 3px ring on focus. */ export const fieldBase = "w-full rounded-md border border-line-strong bg-surface text-base text-fg outline-none transition-[border,box-shadow] " + "placeholder:text-fg-muted data-hovered:border-fg-disabled " + "data-focused:border-accent data-focused:shadow-focus data-focus-within:border-accent data-focus-within:shadow-focus " + "data-invalid:border-error data-invalid:data-focused:shadow-focus-error " + "data-disabled:border-line data-disabled:bg-subtle data-disabled:text-fg-disabled data-disabled:placeholder:text-fg-disabled"; export function Label({ className, children }: { className?: string; children: ReactNode }) { return <AriaLabel className={cx("text-sm font-medium text-fg", className)}>{children}</AriaLabel>; } export function Description({ children }: { children: ReactNode }) { return ( <Text slot="description" className="text-sm text-fg-muted"> {children} </Text> ); } export function ErrorMessage({ children }: { children?: ReactNode }) { return <FieldError className="text-sm text-error-text">{children}</FieldError>; }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | — | Visible label. |
| description | string | — | Helper text under the field. |
| errorMessage | string | — | Marks the field invalid and shows the message. |
| icon | ReactNode | — | Leading icon. |
| trailing | ReactNode | — | Trailing content, e.g. a Kbd. |
| isDisabled | boolean | — | Disables the field. |