# Textarea

> Auto-resizing textarea for React and shadcn: it grows with its text on a spring, with a character counter whose digits roll.

A textarea that grows with its text on a smooth height spring instead of jumping a line at a time. The character counter rolls its digits and turns warning-coloured at 90%.

Also known as an autosize textarea.

- Tier: Free (MIT)
- Interaction: Type
- Page: https://eased.dev/components/textarea
- Installs: @base-ui/react, motion
- Registry: https://eased.dev/r/textarea.json

## Install

```bash
npx shadcn add https://eased.dev/r/textarea.json
```

A multi-line text input on Base UI's Field.Control that grows with its text on a spring, with an optional character counter.

## When to use

- Free text that runs to a few lines: a reply to a support ticket, a review, a note on an order.
- Text with a length limit people should see as they type, such as a 280-character post: set `maxLength` and the counter turns on.
- A box that should start small and grow as people write, up to a cap, rather than a fixed tall box.

## When not to use

- A single line of text, such as a name or an email address: use an [Input](/components/input).
- A chat message box with send, attachments and keyboard submit: use a [Composer](/components/composer).
- Rich text with formatting: a textarea holds plain text only.

## Usage

```tsx reply.tsx
import { useState } from "react";
import { Field } from "@/components/eased/field/field";
import { Textarea } from "@/components/eased/textarea/textarea";

export function Reply() {
  const [text, setText] = useState("");
  return (
    <Field label="Reply">
      <Textarea value={text} onValueChange={setText} maxLength={280} minRows={2} maxRows={6} placeholder="Write a reply…" />
    </Field>
  );
}
```

## Examples

### Without a counter

`showCount={false}` keeps the native limit but hides the counter, for limits people are unlikely to reach.

```tsx
<Field label="Delivery note" description="Gate codes, where to leave it.">
  <Textarea name="note" maxLength={500} showCount={false} minRows={2} />
</Field>
```

### Standalone

Outside a Field, name it with `aria-label` and drive the error state with `invalid`.

```tsx
<Textarea aria-label="Feedback" size="sm" minRows={4} invalid={tooShort} />
```

## API reference

### Textarea

| Prop | Type | Default | Description |
|---|---|---|---|
| `minRows` | `number` | `3` | Height when empty, in lines. |
| `maxRows` | `number` | `8` | Grows up to this many lines, then scrolls. |
| `value` | `string` | | Controlled text. |
| `defaultValue` | `string` | | Uncontrolled starting text. |
| `onValueChange` | `(value: string) => void` | | Called with the new text on every change. |
| `maxLength` | `number` | | The native limit. Turns the counter on. |
| `showCount` | `boolean` | `maxLength !== undefined` | Shows a `count/max` counter under the text. It needs `maxLength`. |
| `invalid` | `boolean` | | Marks the textarea invalid outside a Field. Inside one, the field's validity drives it. |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Type size, radius and padding, matching Input. |
| `className` | `string` | `""` | Classes for the bordered shell. |
| `controlClassName` | `string` | `""` | Classes for the `<textarea>` itself. |

Every other `<textarea>` prop passes through (`name`, `placeholder`, `disabled`, `onKeyDown` …) except `rows`, which `minRows` sets.

## Accessibility

- Inside a Field, Base UI ties the label to the textarea and points `aria-describedby` at the description and error. Outside one, pass `aria-label`.
- The counter is hidden from screen readers. A status line announces only "Approaching the 280 character limit" at 90% and "Character limit reached" at the limit, not every keystroke.
- The counter turns warning-coloured at 90%, and the native limit stops typing at `maxLength`.
- Text is 16px on touch screens so iOS does not zoom in on focus.

## Motion

As you type, the textarea itself is sized at once, so the caret never scrolls out of view, and a clip around it springs to the new height on the smooth spring instead of jumping a line at a time. A controlled value that changes without typing (a reset, an inserted template) springs the same way; a change of width re-measures without animating. The counter's digits roll in the direction of change on the snappy spring, and its colour changes over 150ms. Focus and error states are the same as [Input](/components/input): a border step, a soft glow, and one 6px shake when it turns invalid. Reduced motion jumps the height, changes the digits in place and drops the shake.

## Notes for AI

Use Textarea for plain multi-line text inside a Field. Set `minRows` and `maxRows` to fit the space, and `maxLength` when there is a real limit; the counter and its announcements come with it.

Do not add your own autosize logic, counter or `aria-live` region, and do not set `rows` or a fixed height: the component measures and springs its own height.

## Related

- [Input](/components/input): a single line of text.
- [Field](/components/field): the label and message line around it.
- [Composer](/components/composer): a chat input with send and attachments.

## Example

`components/eased/textarea/textarea-demo.tsx`

```tsx
"use client";

import { useEffect, useRef, useState } from "react";
import { Avatar } from "../avatar/avatar";
import { Button } from "../button/button";
import { Field } from "../field/field";
import { DemoFrame } from "../lib/demo-frame";
import { Textarea } from "./textarea";

const MAX = 280;
const TEMPLATE =
  "Thanks for flagging this, Maya. The export fails when a sheet name contains a slash, so the fix ships in tomorrow’s release. Until then, renaming the sheet works. I’ll reply here once it’s live.";

export function TextareaDemo() {
  const [value, setValue] = useState("");
  const [state, setState] = useState<"idle" | "sending" | "sent">("idle");
  const timers = useRef<number[]>([]);
  useEffect(() => () => timers.current.forEach(clearTimeout), []);

  const send = () => {
    if (!value.trim()) return;
    setState("sending");
    timers.current.push(
      window.setTimeout(() => {
        setState("sent");
        setValue("");
        timers.current.push(window.setTimeout(() => setState("idle"), 1600));
      }, 900),
    );
  };

  return (
    <DemoFrame title="Reply to Maya Chen" meta="#4821">
      <div className="flex min-h-0 flex-1 flex-col gap-4 p-4">
        <div className="flex gap-3">
          <Avatar name="Maya Chen" size="md" />
          <div className="min-w-0">
            <p className="text-ui-sm text-text-muted">Maya Chen · 2h ago</p>
            <p className="text-ui text-pretty text-text-secondary">
              Exporting to CSV fails on the “Q3/Q4 forecast” sheet. Other sheets are fine.
            </p>
          </div>
        </div>

        <Field label="Reply">
          <Textarea
            value={value}
            onValueChange={setValue}
            maxLength={MAX}
            minRows={2}
            maxRows={6}
            placeholder="Write a reply…"
            onKeyDown={(e) => {
              if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) send();
            }}
          />
        </Field>

        <div className="flex items-center gap-2">
          <Button variant="ghost" size="sm" edge="start" onClick={() => setValue(TEMPLATE)}>
            Insert template
          </Button>
          <div className="flex-1" />
          <Button
            variant="primary"
            size="sm"
            loading={state === "sending"}
            disabled={!value.trim() && state === "idle"}
            focusableWhenDisabled
            onClick={send}
          >
            {state === "sent" ? "Sent" : "Send reply"}
          </Button>
        </div>
        <span role="status" className="sr-only">
          {state === "sent" ? "Reply sent" : ""}
        </span>
      </div>
    </DemoFrame>
  );
}
```
