Textarea
A field that lets users enter several lines of text, such as a note.
A textarea takes several lines of text from users, such as a note, a reason or a message. It accepts every attribute of the native textarea element, fills the width of its container and grows with the text that users enter. A label names the text that the textarea asks for, and htmlFor on the label refers to the id of the textarea, so a click on the label moves the focus into the textarea.
Usage
Examples
With Placeholder
Some entries are easier to write when users know what to include, such as the details a complaint needs. While the textarea is empty, placeholder offers such a hint, and the hint disappears as soon as users type, so the label still names what the textarea asks for.
Default Value
Prepared text spares users from writing the same words again, such as the standard note on a recurring order. With defaultValue the textarea starts with that text, and users adjust only what differs this time.
Controlled
Sometimes the application needs the text while users are still writing it, for example to save a draft or to allow sending only once there is something to send. Through value and onChange it holds the text itself, so other parts of the interface can read, replace or clear it.
Disabled
Not every note applies to every order, such as a note for the courier when users collect the goods in the store. Marked as disabled, the textarea accepts neither focus nor input and exposes its state to assistive technology. Its text also stays out of the submitted form, so the order carries no note that no longer applies.
Read-Only
Approved texts, such as a statement that a store manager has signed, belong in front of users without being open to change. Unlike a disabled textarea, one with readOnly stays focusable, so users reach it with the keyboard, and the form submits its text together with the other values.
Invalid
Before a form goes out, users need to see which text still falls short, such as a report that lacks a required detail. Once aria-invalid is set, the textarea shows the error and reports it to assistive technology, so users find the entry that needs their attention.
API Reference
| Prop | value |
|---|---|
| Type | string | readonly string[] | number |
| Default | – |
| Description | Sets the value of the textarea and makes it controlled. Update it in onChange. |
| Prop | defaultValue |
|---|---|
| Type | string | number | readonly string[] |
| Default | – |
| Description | Sets the value of the textarea at first render. The textarea then tracks its value itself. |
| Prop | onChange |
|---|---|
| Type | (event: ChangeEvent<HTMLTextAreaElement>) => void |
| Default | – |
| Description | Runs when users change the value. It receives the change event, and event.target.value holds the value that follows. |
| Prop | placeholder |
|---|---|
| Type | string |
| Default | – |
| Description | Shows a hint in muted text while the textarea is empty. The hint disappears as soon as users type, so it doesn't replace the label. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from focusing and changing the textarea, dims it and exposes the disabled state to assistive technology. A disabled textarea is not submitted with the form. |
| Prop | readOnly |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from changing the value. Unlike a disabled textarea, it stays focusable and is submitted with the form. |
| Prop | required |
|---|---|
| Type | boolean |
| Default | false |
| Description | Requires users to fill in the textarea before they can submit the form. |
| Prop | aria-invalid |
|---|---|
| Type | boolean | "false" | "true" | "grammar" | "spelling" |
| Default | – |
| Description | Marks the value as invalid for assistive technology. With true, the border takes the destructive color. |