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.

Search field

Optional 16px leading icon and trailing content.

States

Enter a valid email.

Installation

Components are copied into your project — no runtime package.

  1. Install the following dependencies:

    terminal
    npm install react-aria-components
  2. Create a input.tsx file 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>
      );
    }
  3. Create a field.tsx file 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>;
    }
  4. Add the theme tokens and the cx helper from Installation if you haven’t yet, then update the import paths to match your project setup.

Props

PropTypeDefaultDescription
labelstring—Visible label.
descriptionstring—Helper text under the field.
errorMessagestring—Marks the field invalid and shows the message.
iconReactNode—Leading icon.
trailingReactNode—Trailing content, e.g. a Kbd.
isDisabledboolean—Disables the field.