# Textarea

Text field over several lines, for a description, a comment or a message. Input's field box: the same raised fill, light edge, 14px text (16px on touch) and states, with container corners that stay finite in the pill preset. One line plus its padding matches the Input height of the same size.

**Dependencies:** npm: 1 direct, 2 total; registry: 2 direct, 2 total.

Native: iOS stable, Android stable.

## Usage

### When to use

- Text over several lines: a description, a comment, a message to the team.
- A value the user pastes in, such as a list of addresses, one per line.

### When not to use

- A single line, such as a name, an email or a search. Use Input.
- Picking from known options. Use Select.

### Native

**Default**

```text
WerewolfTextarea(value: note, onValueChange: { note = $0 }, placeholder: "Add a comment")
```

```text
WerewolfTextarea(value = note, onValueChange = { note = it }, placeholder = "Add a comment")
```

**Six lines**

```text
WerewolfTextarea(value: note, onValueChange: { note = $0 }, rows: 6)
```

```text
WerewolfTextarea(value = note, onValueChange = { note = it }, rows = 6f)
```

## Variants

### size

Padding and minimum height, matching the Input of the same size. Use the size of the other fields in the form.

Values: `sm`, `md`, `lg`, `xl`. Default: `md`.

### resize

Which way the user can drag the corner. vertical keeps the width of the form; none for a fixed box, such as a chat composer.

Values: `none`, `vertical`, `both`. Default: `vertical`.

## Examples

### Default

```tsx
<Field className="w-full max-w-sm">
  <FieldLabel>Description</FieldLabel>
  <FieldControl>
    <Textarea placeholder="What is this project about?" />
  </FieldControl>
  <FieldDescription>Shown on the project card.</FieldDescription>
</Field>
```

### With an error

The error text marks the textarea invalid and is read after its name.

```tsx
<Field className="w-full max-w-sm" required>
  <FieldLabel>Reason for leaving</FieldLabel>
  <FieldControl>
    <Textarea rows={4} />
  </FieldControl>
  <FieldError>Tell us in a sentence or two.</FieldError>
</Field>
```

### Read only

Focusable and copyable, but not editable.

```tsx
<Field className="w-full max-w-sm">
  <FieldLabel>Webhook payload</FieldLabel>
  <FieldControl>
    <Textarea readOnly rows={4} defaultValue="event: project.created" />
  </FieldControl>
</Field>
```

### Disabled

```tsx
<Field className="w-full max-w-sm" disabled>
  <FieldLabel>Notes</FieldLabel>
  <FieldControl>
    <Textarea defaultValue="Archived projects can't be edited." />
  </FieldControl>
</Field>
```

### With a character count

maxLength sets the limit; showCount shows it inside the field.

```tsx
<div className="flex w-full max-w-sm flex-col gap-xs">
  <label htmlFor="bio" className="text-sm text-text-secondary">Bio</label>
  <Textarea id="bio" maxLength={160} showCount defaultValue="Product designer building Werewolf." />
</div>
```

## Do and don't

### Do

- Put it in a Field, so it has a visible label and its description and error are linked.
- Set rows for the text you expect, so the box shows how much to write.
- Use the same size as the other fields in the form.

### Don't

- Don't use it for a single line, such as a name or an email; use Input.
- Don't use a placeholder instead of a label.
- Don't make Enter submit the form; people expect a new line.

## Props

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `size` | `enum` | `sm`, `md`, `lg`, `xl` | `md` | Padding and minimum height, matching the Input of the same size. Use the size of the other fields in the form. |
| `resize` | `enum` | `none`, `vertical`, `both` | `vertical` | Which way the user can drag the corner. vertical keeps the width of the form; none for a fixed box, such as a chat composer. Not generated for iOS and Android. |
| `rows` | `number` |  | `3` | Visible lines before the text scrolls. Pick it for the text you expect: 3 for a comment, 6 or more for a description. |
| `disabled` | `boolean` |  | `false` | Can't be focused or edited. Prefer readOnly for a value the user should still read and copy. |
| `readOnly` | `boolean` |  | `false` | Can be focused, scrolled and copied, but not edited. Same look as an editable textarea. |
| `maxLength` | `number` |  |  | Native limit on the number of characters. With showCount, the count reads 34 / 160. Not generated for iOS and Android. |
| `showCount` | `boolean` |  | `false` | Shows the number of characters typed at the bottom end of the field, out of maxLength when it is set. The textarea is described by the count; a screen reader hears the characters left only near the limit, once typing pauses. Not generated for iOS and Android. |
| `countLabel` | `function` |  |  | What a screen reader hears near the limit, given the characters left. Defaults to "12 characters left"; pass a translated function on a page in another language. Not generated for iOS and Android. |
| `invalid` | `boolean` |  | `false` | Sets aria-invalid, which draws the danger border. Pair it with error text in color-text-danger linked through aria-describedby. |
| `value` | `string` |  |  | Native only: the text in the field. Pair it with onValueChange; the field keeps no state of its own. Only on iOS, Android. |
| `onValueChange` | `function` |  |  | Native only: called with the new text after every edit. Only on iOS, Android. |
| `placeholder` | `string` |  |  | Native only: hint text shown while the field is empty. On web it is the placeholder attribute. Only on iOS, Android. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | The textarea element: raised fill, light edge, radius-container, 14px text at body leading (16px on touch, so iOS doesn't zoom). Never shorter than size-element-* of its size. |
| `placeholder` | Hint text shown when the value is empty. Colored with text-secondary, so it reaches 4.5:1 on the raised fill. |
| `group` | The field box when showCount is set: a wrapper with the textarea's fill, border, radius and padding, showing its focus, disabled look and danger border through :has(). className lands here. |
| `count` | The character count at the bottom end of the group, in mono xs text-tertiary with tabular figures. |

## Accessibility

Role: `textbox`

| Keys | Action |
| --- | --- |
| `Tab` | Moves focus in and out of the textarea; inside it, Tab is not captured. |
| `Enter` | Starts a new line. It never submits the form. |

- Name it with a visible label. Inside a Field, FieldLabel points at it and FieldControl links its description and error.
- A placeholder is a hint, not a label: it disappears as soon as the user types.
- aria-invalid shows the danger border; pair it with error text, since the border alone relies on color. A FieldError does both.
- A textarea is a replaced element, so it has no ::before hit area. It is never shorter than a control of its size.
- Disabled text can still scroll, so nothing in a long value is lost from view.

## Install

```bash
npx werewolf-ui add textarea
```

Run `npx werewolf-ui init` once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See [Installation](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.

```bash
npx werewolf-ui add textarea --platform ios
npx werewolf-ui add textarea --platform android
```

For iOS and Android, run `npx werewolf-ui init --platform ios` or `npx werewolf-ui init --platform android` once, then add with `--platform`. See [Installation](https://www.werewolf-ui.dev/docs/installation.md).
