# Text area

A multi-line text input that grows with its content, with an optional character count.

- Family: form
- Import: `import { TextArea } from "@senvenli/react/form";`
- Page: https://design.senvenli.com/docs/components/text-area
- JSON: https://design.senvenli.com/docs/components/text-area.json

## Example: Longer text

Grows with its content, then scrolls.

```tsx
import { TextArea } from "@senvenli/react/form";

export default function Example() {
  return (
    <TextArea
      label="Notes for the customer"
      placeholder="Payment terms, delivery details…"
      description="Shown at the bottom of the invoice."
      isOptional
    />
  );
}
```

## Examples

### With a limit

`maxLength` shows the count; text past it is kept and marks the field invalid.

```tsx
import { TextArea } from "@senvenli/react/form";

export default function Example() {
  return (
    <TextArea
      label="Project summary"
      maxLength={160}
      defaultValue="A new storefront for the spring catalog, with faster checkout and saved carts."
    />
  );
}
```

### Invalid

The error says what is missing.

```tsx
import { TextArea } from "@senvenli/react/form";

export default function Example() {
  return (
    <TextArea
      label="Reason for the refund"
      defaultValue="Late"
      isInvalid
      errorMessage="Describe what happened in a sentence or two, so finance can approve it."
    />
  );
}
```

## Guidelines

### When to use it

- Longer free text: a message, notes, a description.

### Use something else when

- [input](https://design.senvenli.com/docs/components/input.md): The answer fits on one line.

## Accessibility

Built in:

- The character count is announced politely as it changes.
- Required fields show "Fill in this field." after a blur or a submit; your own `errorMessage` replaces it.

You provide:

- A visible label.

## API reference

### TextArea

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| label | `React.ReactNode` |  | yes |  |
| isLabelHidden | `boolean` |  | no | Keeps the label for screen readers only: it still names the field, but takes no space. For a field whose purpose the surface already shows, such as a chat reply box under its conversation. A visible label stays the default. |
| description | `React.ReactNode` |  | no |  |
| errorMessage | `React.ReactNode` |  | no |  |
| isOptional | `boolean` |  | no |  |
| placeholder | `string` |  | no |  |
| maxLength | `number` |  | no | Shows the counter. The user may type or paste past it; the field turns invalid and blocks on submit, so pasted text is never cut silently. |
| showCounter | `boolean` |  | no | Shows the "89 / 500" count under the field; `true` by default whenever `maxLength` is set. `false` hides only the visible count: the limit still marks the field invalid past `maxLength`, and screen readers still hear when it is exceeded. |
| requiredValidation | `RequiredValidation` |  | no | Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See {@link RequiredValidation} for the whole contract. |
| radius | `ComponentRadius` |  | no | Corner radius: `none`, `small`, `medium` (the design), `large` or `full`. The provider's default otherwise. |

Behavior props from React Aria:

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| defaultValue | `string` |  | no | The default value (uncontrolled). |
| autoFocus | `boolean` |  | no | Whether the element should receive focus on render. |
| enterKeyHint | `"enter" \| "done" \| "go" \| "next" \| "previous" \| "search" \| "send"` |  | no | An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint). |
| spellCheck | `string` |  | no | An enumerated attribute that defines whether the element may be checked for spelling errors. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck). |
| autoCorrect | `string` |  | no | An attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete). |
| inputMode | `"none" \| "search" \| "text" \| "tel" \| "url" \| "email" \| "numeric" \| "decimal"` |  | no | Hints at the type of data that might be entered by the user while editing the element or its contents. See [MDN](https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute). |
| onCopy | `ClipboardEventHandler<HTMLInputElement>` |  | no | Handler that is called when the user copies text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncopy). |
| onCut | `ClipboardEventHandler<HTMLInputElement>` |  | no | Handler that is called when the user cuts text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncut). |
| onPaste | `ClipboardEventHandler<HTMLInputElement>` |  | no | Handler that is called when the user pastes text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/onpaste). |
| onCompositionEnd | `CompositionEventHandler<HTMLInputElement>` |  | no | Handler that is called when a text composition system completes or cancels the current text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionend_event). |
| onCompositionStart | `CompositionEventHandler<HTMLInputElement>` |  | no | Handler that is called when a text composition system starts a new text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event). |
| onCompositionUpdate | `CompositionEventHandler<HTMLInputElement>` |  | no | Handler that is called when a new character is received in the current text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionupdate_event). |
| onFocus | `(e: FocusEvent<HTMLInputElement, Element>) => void` |  | no | Handler that is called when the element receives focus. |
| onBlur | `(e: FocusEvent<HTMLInputElement, Element>) => void` |  | no | Handler that is called when the element loses focus. |
| onChange | `(value: string) => void` |  | no | Handler that is called when the value changes. |
| onBeforeInput | `FormEventHandler<HTMLInputElement>` |  | no | Handler that is called when the input value is about to be modified. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event). |
| onInput | `FormEventHandler<HTMLInputElement>` |  | no | Handler that is called when the input value is modified. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event). |
| onSelect | `ReactEventHandler<HTMLInputElement>` |  | no | Handler that is called when text in the input is selected. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/select_event). |
| isDisabled | `boolean` |  | no | Whether the input is disabled. |
| onFocusChange | `(isFocused: boolean) => void` |  | no | Handler that is called when the element's focus status changes. |
| type | `(string & {}) \| "search" \| "text" \| "tel" \| "url" \| "email" \| "password"` |  | no | The type of input to render. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype). |
| form | `string` |  | no | The `<form>` element to associate the input with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form). |
| name | `string` |  | no | The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). |
| value | `string` |  | no | The current value (controlled). |
| excludeFromTabOrder | `boolean` |  | no | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. |
| isRequired | `boolean` |  | no | Whether user input is required on the input before form submission. |
| isReadOnly | `boolean` |  | no | Whether the input can be selected but not changed by the user. |
| isInvalid | `boolean` |  | no | Whether the value is invalid. |
| validate | `(value: string) => true \| ValidationError \| null \| undefined` |  | no | A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if `validationBehavior="native"`. For realtime validation, use the `isInvalid` prop instead. |
| validationBehavior | `"aria" \| "native"` |  | no | Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA. |
| autoComplete | `string` |  | no | Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). |
| minLength | `number` |  | no | The minimum number of characters required by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefminlength). |
| pattern | `string` |  | no | Regex pattern that the value of the input must match to be valid. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefpattern). |

Also takes 84 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-disabled`, `--ds-background-input`, `--ds-background-input-hovered`, `--ds-background-neutral-pressed`, `--ds-background-neutral-subtle-hovered`, `--ds-border`, `--ds-border-bold`, `--ds-border-danger`, `--ds-border-focused`, `--ds-easing-standard`, `--ds-icon-subtle`, `--ds-radius-control-medium`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-size-control`, `--ds-size-control-compact`, `--ds-size-control-large`, `--ds-size-icon`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-surface-sunken`, `--ds-text`, `--ds-text-danger`, `--ds-text-disabled`, `--ds-text-subtle`, `--ds-text-subtlest`

## Related

- [input](https://design.senvenli.com/docs/components/input.md)
