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.
Preview
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.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| size | Yes | Yes | Yes | |
| resize | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| rows | Yes | Yes | Yes | |
| disabled | Yes | Yes | Yes | |
| readOnly | Yes | Yes | Yes | |
| maxLength | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| showCount | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| countLabel | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| invalid | Yes | Yes | Yes | |
| value | No | Yes | Yes | Only on iOS, Android. |
| onValueChange | No | Yes | Yes | Only on iOS, Android. |
| placeholder | No | Yes | Yes | Only on iOS, Android. |
Variants
size
Padding and minimum height, matching the Input of the same size. Use the size of the other fields in the form.
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.
Examples
Default
With an error
The error text marks the textarea invalid and is read after its name.
Read only
Focusable and copyable, but not editable.
Disabled
With a character count
maxLength sets the limit; showCount shows it inside the field.
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
npx werewolf-ui add textareaRun 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 for requirements and the alternative registry setup.