Forms

Textarea

Multiline field, 14 Regular at 140% line height, minimum 96px tall.

react-aria-components

Preview

Installation

Components are copied into your project — no runtime package.

  1. Install the following dependencies:

    terminal
    npm install react-aria-components
  2. Create a textarea.tsx file and paste the following code into it.

    src/components/ui/textarea.tsx
    "use client";
    
    import { TextArea as AriaTextArea, TextField, type TextFieldProps } from "react-aria-components";
    import { cx } from "@/utils/cx";
    import { Description, ErrorMessage, Label, fieldBase } from "./field";
    
    export interface TextareaProps extends Omit<TextFieldProps, "className" | "children"> {
      label?: string;
      description?: string;
      errorMessage?: string;
      placeholder?: string;
      rows?: number;
      className?: string;
    }
    
    /** Multiline field — 14 Regular at 140% line height, min height 96. */
    export function Textarea({ label, description, errorMessage, placeholder, rows = 4, className, ...props }: TextareaProps) {
      return (
        <TextField {...props} isInvalid={props.isInvalid ?? Boolean(errorMessage)} className={cx("flex flex-col gap-2", className)}>
          {label && <Label>{label}</Label>}
          <AriaTextArea placeholder={placeholder} rows={rows} className={cx(fieldBase, "min-h-24 resize-y px-3 py-2.5 leading-[1.4]")} />
          {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.