<!-- index: /slotted/llms.txt -->
# textarea

`data-ui="textarea"` · Multi-line text input.

## Import

```tsx
import { Textarea, TextareaDefaultsProvider } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';
import { Textarea } from '@slotted/react/textarea';

export default function TextareaBasic() {
  return (
    <Field>
      <FieldLabel>Delivery instructions</FieldLabel>
      <Textarea placeholder="Gate code, loading dock, opening hours" />
      <FieldDescription>Printed on the packing slip for the carrier.</FieldDescription>
    </Field>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | textarea, or the element render returns | yes |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `value` | `string` | — | Textarea | Makes the value controlled for the life of the component. Without it the element keeps its own value, and a native form reset restores defaultValue. |
| `defaultValue` | `string` | — | Textarea | The value an uncontrolled textarea starts from. It is read once and written to the element, which is what a form reset returns to. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Textarea, TextareaDefaultsProvider | The step of the control scale. When unset, the textarea takes the size of its field, then of the provider. The vertical padding is derived from the step, so a textarea of one row is as tall as a text field of the same step at every density. |
| `variant` | `'outline' \| 'subtle' \| 'plain'` | outline | Textarea, TextareaDefaultsProvider | How much frame the textarea draws: the three frames of the text field, read from the same tokens. When unset, the textarea takes the variant of the provider. |
| `mono` | `boolean` | false | Textarea, TextareaDefaultsProvider | Sets the value in the monospaced font with tabular figures, for a payload, a template or a diff. |
| `resize` | `'block' \| 'none' \| 'both'` | block | Textarea, TextareaDefaultsProvider | Which way the resize handle drags. The default is block rather than the platform’s both, because a textarea wider than its field breaks the field’s grid. While autoSize is on, the handle is removed. |
| `autoSize` | `boolean` | false | Textarea | Grows the textarea with its content through CSS field-sizing, with no measurement in script. rows becomes the floor and maxRows the ceiling. |
| `rows` | `number` | 3 | Textarea | The starting height in lines, and the floor while autoSize is on. The default is 3 rather than the platform’s 2, because a box of two rows reads as a mistyped input. |
| `maxRows` | `number` | 12 | Textarea | The ceiling autoSize grows to, in lines; past it the textarea scrolls. It cannot be removed, because a textarea that grows without limit pushes the page out from under the caret. |
| `showCount` | `boolean` | false | Textarea | Publishes the length of the value to the field around it, which draws the count at the end of its label row. |
| `countMax` | `number` | maxLength | Textarea | The limit the count is measured against; it defaults to maxLength. Without maxLength it is a soft limit: the value may pass it, and the count is then drawn as invalid. |
| `disabled` | `boolean` | from the field, or false | Textarea | Unset rather than false, so the textarea follows the field around it. When set, it wins over the field and writes the native disabled. |
| `readOnly` | `boolean` | from the field, or false | Textarea | Unset rather than false, so the textarea follows the field around it. Writes the native readonly: the textarea stays focusable, selectable and submitted, and keeps its resize handle. |
| `invalid` | `boolean` | from the field, or false | Textarea | Unset rather than false, so the textarea follows the field around it. Writes aria-invalid and data-invalid. |
| `required` | `boolean` | — | Textarea | The element’s own attribute, passed through unchanged; Textarea never writes it. Inside a required field, the textarea receives aria-required instead. |
| `render` | `(props: TextareaRootProps) => ReactNode` | — | Textarea | Renders another element in place of the textarea and passes it every attribute, including the two custom properties that carry rows and maxRows. The props are typed as HTMLAttributes<HTMLElement>, so they spread onto any element. |
| `ref` | `Ref<HTMLTextAreaElement>` | — | Textarea | Reaches the textarea element. focus(), select() and setSelectionRange() are the element’s own, so Textarea adds no imperative handle. |
| `TextareaDefaultsProvider` | `{ size, variant, mono, resize }` | — | a subtree | Sets size, variant, mono and resize once for every textarea under it. A textarea that states a value keeps it, and a textarea inside a field takes the field’s size over the provider’s. |
| `useField()` | `() => FieldContextValue \| undefined` | — | inside a Field | What Textarea reads inside a Field to wire itself: the identifier, the description, the disabled, read-only, invalid and required states, and the channel it publishes its count on. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onValueChange` | `(value: string, request: ChangeRequest<string>)` | Before the value moves. request.value is the new value and request.previous the value it replaces. request.reason is always keyboard, because only an edit in the textarea moves the value, and request.source is the originating event. request.cancel() refuses the change: the count does not move, and an uncontrolled element keeps what was typed. |
| `onChange, onInput, onFocus, onBlur` | `the element’s own events` | Whenever the textarea fires them. Textarea composes your handler with its own instead of replacing it: yours runs first, and always runs. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `sm`, `md`, `lg` | `md` |
| `variant` | `outline`, `subtle`, `plain` | `outline` |
| `resize` | `block`, `none`, `both` | `block` |

## Rules

- The WAI-ARIA Authoring Practices define no pattern for a multi-line text control. Textarea follows the HTML specification for the element and the ARIA textbox role, whose aria-multiline the native element supplies.
- Inside a field, the textarea takes its accessible name from the field’s label, whose for attribute points at the identifier the field generates. aria-describedby lists any value you write first, then the ones the field adds: help, description, count and error.
- A required field sets aria-required, not the native required. The native attribute turns on browser constraint validation and changes how the form submits; write required on the textarea to opt in, and it is kept. disabled and readonly are the native attributes.
- Enter adds a line and never submits the form. WAI-ARIA describes this as the difference between a single-line and a multi-line text control, and a comment box that submitted on Enter would lose what was being written.
- Tab moves focus out of the textarea. No key is bound, so no shortcut holds keyboard focus inside it.
- Growth with the content is CSS, not script: the textarea takes its new height with no animation, so a screen reader announces nothing and a reader who asked for reduced motion sees no movement.

## Tokens

`--slotted-border-subtle`, `--slotted-control-border-color`, `--slotted-control-border-width`, `--slotted-control-focus-ring-offset`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-height-lg`, `--slotted-control-height-md`, `--slotted-control-height-sm`, `--slotted-control-invalid-edge-width`, `--slotted-control-padding-inline-lg`, `--slotted-control-padding-inline-md`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-control-shadow`, `--slotted-control-shadow-focus-geometry`, `--slotted-control-surface`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-focus-ring-color`, `--slotted-focus-ring-color-invalid`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-family-mono`, `--slotted-line-height-md`, `--slotted-radius-none`, `--slotted-surface-sunken`, `--slotted-text`, `--slotted-text-muted`, `--slotted-textarea-background`, `--slotted-textarea-border-color`, `--slotted-textarea-color`, `--slotted-textarea-disabled-background`, `--slotted-textarea-disabled-border-color`, `--slotted-textarea-disabled-color`, `--slotted-textarea-hover-border-color`, `--slotted-textarea-invalid-border-color`, `--slotted-textarea-invalid-edge-width`, `--slotted-textarea-invalid-focus-ring-color`, `--slotted-textarea-line-height`, `--slotted-textarea-max-rows`, `--slotted-textarea-placeholder-color`, `--slotted-textarea-plain-hover-background`, `--slotted-textarea-radius`, `--slotted-textarea-readonly-background`, `--slotted-textarea-rows`, `--slotted-textarea-shadow`, `--slotted-textarea-subtle-background`, `--slotted-textarea-subtle-border-color`, `--slotted-textarea-subtle-hover-background`, `--slotted-tone-accent-border`, `--slotted-tone-danger-border`, `--slotted-tone-secondary-subtle-hover`

## Examples

See [textarea.examples.md](./textarea.examples.md).
