<!-- generated by scripts/gen-docs.mjs from docs/system/textarea.md. Edit the source and rerun. -->
# Textarea

## Description
Takes text that runs past one line, such as notes or an agenda, and grows with it.

`import { Textarea } from "@/components/cobalt/ui/textarea"`, source `registry/cobalt/ui/textarea.tsx`, status `ready-with-gaps`.
Foundation: `shadcn textarea (base-luma, base)`. Traps checked: `trap/field-label`, `trap/label-unbound`, `trap/field-input-type`, `trap/field-affix-focus`, `trap/field-form-enter`, `trap/field-error-link`, `trap/field-error-timing`, `trap/field-keeps-input`, `trap/touch-input-zoom`, `trap/touch-autofocus`, `trap/control-height`, `trap/focus-ring-shape`, `trap/hover-beats-focus`, `trap/disabled-still-hovers`, `trap/required-everywhere`.

Where each trap is answered: `trap/field-label` and `trap/label-unbound` through `rule/input-has-a-label`; `trap/field-form-enter` in `rule/textarea-submit-is-a-button`; `trap/field-error-link` through `rule/input-error-is-linked`; `trap/field-error-timing` in Field's `rule/field-error-when-settled`; `trap/field-keeps-input` through `rule/input-keeps-the-value-on-failure`; `trap/touch-input-zoom` in States, 16px text at 390px measured; `trap/touch-autofocus` through `rule/input-no-autofocus-on-a-page`; `trap/required-everywhere` in Label's `rule/label-marks-the-rarer`. Not applicable: `trap/field-input-type`, a textarea has no `type` and its text is prose, so spellcheck stays on; `trap/field-affix-focus`, nothing sits inside a textarea's box; `trap/control-height`, the box starts at 64px and sits alone in its row; `trap/focus-ring-shape`, focus is a box-shadow on the box itself, so the edge and ring follow its rounded corners (D40); `trap/hover-beats-focus`, hover changes nothing on the box, so it cannot beat focus (D40); `trap/disabled-still-hovers`, hover changes nothing on the box, enabled or not (D40).

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| A native `<textarea>` with every attribute passed through, `field-sizing: content` so it grows with its text, `resize-none`, drawn through Base UI's `Field.Control` (`render={<textarea />}`), so inside a `Field` it registers itself: the label's `for`, `aria-describedby`, `aria-invalid` and `disabled` reach it with no wrapper | The filled look, `bg-input/50` with a transparent border, the same at rest, under the pointer and while focused; after you reach the field with the Tab key, focus draws the `field-focus` utility from `registry/cobalt/styles.css`, an inset 1px edge in `--primary` and a 3px ring of `--primary` at 20 percent outside it, and on an invalid field the same edge and ring in `--destructive`; a click into the field shows only the caret, because `registry/cobalt/lib/focus-source.ts` (`trackFocusSource`, started from an effect in the component, so it is a client component) sets `data-focus-source` on the root element to `keyboard` on a Tab key press and to `pointer` on a pointer press, and the utility draws only under `:root[data-focus-source="keyboard"]` (D40, which replaces the earlier "no ring, darker fill" text of person D11 and audit Fix now 6); a 64px starting height from `min-h-16` with 7px of padding above and below the text, so the first line sits 8px from the top edge as Input's text does and a form's first lines line up; `text-base` below `md` and `text-sm` from `md` up, so a phone does not zoom on focus; the invalid wash `aria-invalid:bg-destructive/10` in place of a red border; the edge and ring ease in on `transition-shadow duration-press`, `--t-press`; `quietAutofill(undefined, autoComplete)` from `registry/cobalt/lib/autofill.ts`, spread before the host's props, which leaves password managers to fill the box and adds `data-1p-ignore`, `data-op-ignore`, `data-bwignore`, `data-lpignore` and `data-form-type="other"` only when `autoComplete` is `off`; whatever a password manager inserts beside the box is taken out of the layout by a rule in `registry/cobalt/base.css` (D37) `max-h-96` with `overflow-y-auto`, so a pasted page scrolls inside a 384px box instead of pushing the label and error off the screen; `unicode-bidi: plaintext`, so each paragraph reads in its own direction (`docs/research/2026-10-16-break-ui-inputs.md`). |

## Examples
A labelled box that starts two lines tall and grows with what is written in it.

Real uses, 0 call sites (`rg -n "<Textarea\b" app docs/system/examples --glob '!docs/system/examples/textarea/*'`): the showcase chrome renders no Textarea of its own, the examples folder does not count, and the registry folder never counts. No other example uses it yet.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/textarea/default.tsx` | default | A labelled box that starts two lines tall and grows with what is written in it |
| Not applicable: the box in default.tsx is empty with a placeholder | state:empty | The placeholder in the muted ink |
| Not applicable: the box in in-field.tsx holds a value | state:filled | The value in the ink |
| `docs/system/examples/textarea/state-invalid.tsx` | state:invalid | A red wash once the box is left empty, with the error linked to it by the Field |
| `docs/system/examples/textarea/state-disabled.tsx` | state:disabled | Disabled through the Field, with the reason under it |
| Not applicable: type into default.tsx and it grows 24px per line | state:grown | The box past its starting height |
| `docs/system/examples/textarea/capped.tsx` | state:capped | Past 15 lines the box stops growing and scrolls inside itself, so its label stays on screen while you write |
| Not applicable: hover is reached with the pointer on any example | state:hover | Nothing changes on the box (D40) |
| Not applicable: focus is reached with a click or Tab on any example | state:focus | The caret after a click; the accent edge and ring too after Tab (D40) |
| `docs/system/examples/textarea/in-field.tsx` | composition:Field | The limit is written in the description, with what is left as you type |

Example: A labelled box that starts two lines tall and grows with what is written in it (`docs/system/examples/textarea/default.tsx`)

```tsx
import { Field, FieldLabel } from "@/components/cobalt/ui/field";
import { Textarea } from "@/components/cobalt/ui/textarea";

export default function Example() {
  return (
    <Field className="w-full max-w-sm">
      <FieldLabel>Notes on this paper</FieldLabel>
      <Textarea placeholder="What the team should know before reading it" />
    </Field>
  );
}
```

Example: The limit is written in the description, with what is left as you type (`docs/system/examples/textarea/in-field.tsx`)

```tsx
import { useState } from "react";

import { Field, FieldDescription, FieldLabel } from "@/components/cobalt/ui/field";
import { Textarea } from "@/components/cobalt/ui/textarea";

const limit = 500;

export default function Example() {
  const [agenda, setAgenda] = useState("Budget for the spring workshop\nRooms for the November reading night");
  return (
    <Field className="w-full max-w-sm">
      <FieldLabel>Agenda</FieldLabel>
      <Textarea value={agenda} maxLength={limit} onChange={(event) => setAgenda(event.target.value)} />
      <FieldDescription className="tabular-nums">
        Up to {limit} characters, {limit - agenda.length} left.
      </FieldDescription>
    </Field>
  );
}
```

## Variants
Not applicable: Textarea has no variant axis. `rows` sets the starting height in lines and the box grows past it with its content.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| empty | no value | type, paste, focus | the placeholder text, the 64px box | screenshot |
| filled | a value | edit, select, copy | the text in the ink | test |
| grown | text past the starting height | keep writing | the box 24px taller per line, no scrollbar and no resize handle | screenshot |
| hover | pointer over, under `(hover: hover)` | click to focus | nothing changes on the box; the fill stays `--input` at 50 percent (D40) | by hand |
| focus | Tab, a click, or a click on the label | type | the caret; after Tab also the `--primary` edge and ring, and a click shows no ring; the fill does not change (D40) | by hand |
| invalid | `aria-invalid` from the host, or from `Field` when a `FieldError` renders | fix the text | the error text tied by `aria-describedby`, read after the name | test |
| disabled | `disabled` | nothing; the box leaves the tab order | half opacity, `cursor: not-allowed` | test |
| read-only | `readOnly` | focus, select and copy, not edit | full opacity and the caret; typing changes nothing | by hand |

Pending is not a state of the box: the form's submit button carries it through `StateButton` (`rule/button-keeps-its-box-when-busy`). The text is 16px at 390px (measured, .design-system/evidence/textarea/grow-lines-390.json), so a phone does not zoom on focus (`trap/touch-input-zoom`).

Example: A red wash once the box is left empty, with the error linked to it by the Field (`docs/system/examples/textarea/state-invalid.tsx`)

```tsx
import { useState } from "react";

import { Field, FieldError, FieldLabel } from "@/components/cobalt/ui/field";
import { Textarea } from "@/components/cobalt/ui/textarea";

export default function Example() {
  const [reason, setReason] = useState("");
  // The box was left empty, so the error shows; it goes as soon as there is text, and comes back
  // only when the box is left empty again.
  const [left, setLeft] = useState(true);
  const shown = left && reason.trim() === "";
  return (
    <Field className="w-full max-w-sm">
      <FieldLabel>Reason for the new dates</FieldLabel>
      <Textarea
        value={reason}
        onChange={(event) => {
          setReason(event.target.value);
          if (event.target.value.trim() !== "") setLeft(false);
        }}
        onBlur={() => setLeft(true)}
      />
      <FieldError reserve>{shown ? "Say why the dates changed, so the host can plan the rooms." : ""}</FieldError>
    </Field>
  );
}
```

Example: Disabled through the Field, with the reason under it (`docs/system/examples/textarea/state-disabled.tsx`)

```tsx
import { Field, FieldDescription, FieldLabel } from "@/components/cobalt/ui/field";
import { Textarea } from "@/components/cobalt/ui/textarea";

export default function Example() {
  return (
    <Field disabled className="w-full max-w-sm">
      <FieldLabel>Dietary needs</FieldLabel>
      <Textarea placeholder="Allergies, or meals to leave out" />
      <FieldDescription>This booking has no meals. Add breakfast to tell the kitchen.</FieldDescription>
    </Field>
  );
}
```

Example: Past 15 lines the box stops growing and scrolls inside itself, so its label stays on screen while you write (`docs/system/examples/textarea/capped.tsx`)

```tsx
import { Field, FieldLabel } from "@/components/cobalt/ui/field";
import { Textarea } from "@/components/cobalt/ui/textarea";

const agenda = [
  "Welcome and apologies",
  "Notes from the September meeting",
  "Actions still open",
  "Filings covered in the third quarter",
  "Refreshing the adviser data",
  "Screener response times",
  "New fund types to track",
  "Fixes to the domicile mapping",
  "Method for holdings overlap",
  "Reading list for October",
  "Review of the liquidity paper",
  "Review of the fee dispersion paper",
  "Hiring for the data team",
  "Budget for the spring workshop",
  "Rooms for the November reading night",
  "Conference travel",
  "Licences for the team's tools",
  "Security review",
  "Any other business",
  "Date of the next meeting",
].join("\n");

export default function Example() {
  return (
    <Field className="w-full max-w-sm">
      <FieldLabel>Agenda</FieldLabel>
      <Textarea defaultValue={agenda} />
    </Field>
  );
}
```

### State precedence
- Disabled and invalid: disabled wins. The wash fades with the box to half opacity, and the host drops the error text while the box is disabled.
- Disabled and focus: disabled wins. A disabled textarea leaves the tab order, so it never holds focus.
- Disabled and hover: disabled wins. The cursor turns to not-allowed and the box stays at rest; hover changes nothing on it in any case (D40).
- Grown and every other state: both show. The height follows the text whatever the state, so a disabled or invalid box still shows all of its text.
- Read-only and invalid: both show. The text stays selectable and the wash marks it.
- Invalid and focus: both show. The wash stays while you type the fix, with the red edge and ring after Tab and only the caret after a click, and the wash leaves when the host clears `aria-invalid` (D40).
- Focus and hover: focus wins, and hover adds nothing. The box does not change under the pointer, so the caret, and the edge and ring after Tab, read the same with or without it (D40).
- Empty and filled: Not applicable: a box is one or the other.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| focus in and out | announce | `--t-press` on `--curve` | box-shadow, after Tab only; a click shows no ring to animate | the same; the edge and ring still ease in |
| valid to invalid and back, and the fade to disabled | announce | none; the wash and the opacity change in the same frame | none | the same |
| a new line typed | announce | `instant`, no transition; the box grows with the text in the same frame | none | the same |

## Props

<!-- Props generated from registry/cobalt/ui/textarea.tsx with TypeScript by scripts/props-table.mjs -->
No props of its own.

Also accepts every native `<textarea>` attribute.

Every native textarea attribute passes through: `rows` (the starting height in lines), `disabled`, `readOnly`, `required`, `maxLength`, `placeholder`, `name`, `aria-*`. `ref` reaches the `<textarea>`. Password managers are left to fill the box; the attributes that tell them to stay out are added only when `autoComplete` is `off`, and anything a password manager inserts beside the box is taken out of the layout by `registry/cobalt/base.css`. `className` is merged last and is for placement, such as `w-full`, or a `max-h-96 overflow-y-auto` cap under `rule/textarea-max-lines`.

## Usage

### When to use
- The user writes more than one line: notes, an agenda, a message, a description.
- The text has line breaks that matter, such as one item per line.

### When not to use
- The value is one line: a name, an address, a URL, an amount. Use Input instead; Enter in a textarea adds a line and never submits.
- The value is one of up to 10 known options. Use Select instead.
- The box needs a name, a description or an error. Use Field instead, which holds the Textarea and wires them to it.

### Rules
- Follows `rule/input-has-a-label`.
- Follows `rule/input-error-is-linked`.
- Follows `rule/input-keeps-the-value-on-failure`.
- `rule/textarea-grows-with-content`: When a Textarea takes a multi-line value, leave the box to grow with its text and set `rows` for the starting height, instead of a fixed `h-*` with a scrollbar, because what the user writes stays in view while they write it, and a fixed box hides the earlier lines at 3 lines of text. Evidence: measured 64px empty and 24px per line with no scrollbar to 34 lines, .design-system/evidence/textarea/grow-lines-390.json; principle heuristic: visibility of system status, the text written so far stays visible. Check: lint rule/component-override on an `h-*` class (scripts/check-system.mjs); review.
  - Don't: `<Textarea className="h-24 overflow-y-auto" />`
  - Do: `<Textarea rows={3} />`
- `rule/textarea-submit-is-a-button`: When a Textarea sits in a form, keep a visible `type="submit"` button instead of submitting on Enter, because Enter in a textarea adds a line and the user expects it to; a shortcut such as Cmd+Enter may sit beside the button, never in place of it. Evidence: principle platform: implicit submission skips multi-line fields, so a form with only a textarea needs its button; principle wcag: 2.1.1 Keyboard, the submit is reachable without a shortcut. Check: review of every form that holds a Textarea.
  - Don't: `<Textarea onKeyDown={(event) => event.key === "Enter" && save()} />`
  - Do: `<Textarea name="agenda" /> <Button type="submit">Save agenda</Button>`

### Content
- Follows `rule/writing-field-label-noun`.
- Follows `rule/writing-placeholder-not-label`.
- `rule/textarea-limit-in-description`: When a Textarea has a length limit, write it in `FieldDescription` as "Up to {n} characters" instead of in the placeholder or in a counter alone, because the placeholder leaves on the first keystroke and a bare counter says nothing about the ceiling until it is hit. Evidence: single use `docs/system/examples/textarea/in-field.tsx:16`, the one limited box in the examples, and the template holds for any limit; principle wcag: 3.3.2 Labels or instructions, the constraint is stated before the entry. Check: review of every `maxLength`.
  - Don't: `<Textarea maxLength={500} placeholder="Agenda (max 500 chars)" />`
  - Do: `<Textarea maxLength={500} /> <FieldDescription>Up to 500 characters.</FieldDescription>`

### Anti-slop
- `rule/textarea-no-resize-handle`: When a Textarea renders, leave `resize-none` and add no `resize-y` or fixed `h-*` through `className`, because the box grows with its text, and a handle on a box that grows on its own gives the user two ways to set one height. Evidence: app 0/5 Textarea uses in the examples add a resize class (`rg -n "<Textarea\b" docs/system/examples`); principle heuristic: aesthetic and minimalist design, one way to size the box. Check: lint rule/component-override (scripts/check-system.mjs).
  - Don't: `<Textarea className="resize-y h-32" />`
  - Do: `<Textarea rows={4} />`

### Limits
- `rule/textarea-max-lines`: When the text may run past 15 lines, keep the built-in cap, `max-h-96` (384px) with its own scroll, and raise it through `className` only in a page that gives the box the whole screen, instead of removing it, because at 35 lines an uncapped box is 866px tall, past the 844px viewport at 390px, and the label and the error leave the screen while the user writes; a pasted 24-item agenda grew an uncapped box to 2,416px at 320px. Evidence: measured 866px at 35 lines and 24px per line from a 64px empty box, .design-system/evidence/textarea/grow-lines-390.json. Check: probe .design-system/scripts/grow-inputs.mjs on the showcase at 390x844; the stress page `/stress/textarea` with the worst data, `docs/research/2026-10-16-break-ui-inputs.md`.
  - Don't: `<Textarea name="minutes" className="max-h-none" />` for meeting minutes that run to 60 lines
  - Do: `<Textarea name="minutes" />`

## Accessibility
Rests on `<textarea>`. Focus is shown by the caret, and after the Tab key also by the `--primary` edge and ring, red on an invalid box (D40); a click shows only the caret, and the fill does not change.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the box | focuses it, places the caret and draws the edge and ring | the box | by hand |
| typing | the box | edits the text | the box | by hand |
| Enter | the box | adds a line; never submits the form | the box | by hand |
| Tab | the box | leaves to the next control; a tab character is never inserted | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| root | textbox, multi-line | the `Label` through `htmlFor`, `FieldLabel`, or `aria-label` | `aria-invalid`, `aria-describedby`, `disabled`, `readonly`, `required` | the name, "edit text, multi-line", the text, "invalid entry" when invalid, then the description and the error | a11y scan |

Contrast: the box shares Input's fill, ink, placeholder and wash tokens, measured on Input at 390px (.design-system/evidence/input/contrast-390.json): the placeholder on the fill 5.13:1 light and 6.6:1 dark; the text on the fill 16.9:1 light and 16.33:1 dark; the text on the invalid wash 15.37:1 light and 17.14:1 dark.

## Tokens
| Part | State | Token |
|---|---|---|
| root | all | `--r-lg`, `--input` at 50 percent, `--foreground`, `--t-press`, `--curve` |
| root | focus after Tab | `--primary` for the 1px edge and, at 20 percent, the 3px ring |
| root | empty | `min-h-16`, 64px measured, with `py-1.75` |
| root | below md | `text-base`, measured 16px at 390px |
| root | md and up | `text-sm` |
| placeholder | empty | `--muted-foreground` |
| root | invalid | `--destructive` at 10 percent, `--foreground` |
| root | invalid focus after Tab | `--destructive` for the edge and, at 20 percent, the ring |
| root | disabled | opacity 50 percent |

## Related
- Input: one line of text, with an icon, a prefix or a button inside its box when it needs one.
- Field: the Textarea with its label, description and error wired.
- CopyButton: copies a long text so a person need not select it.
- Composer: writes a message or a prompt: a field that grows, files, emoji and a send button that says why it waits.
- FileDrop: takes files by drop or by a button, and shows each one's upload as it goes.
- InlineEdit: a value edited where it is read, saved on Enter or when the field is left.
