# TextArea

The TextArea component is a multi-line text input that allows users to enter and edit longer text content. It supports auto-sizing functionality and various text input features like validation and formatting.

## Examples

### Identifier

For a multi-line value that is still an identifier, such as a list of keys, `isIdentifier` keeps a phone keyboard from capitalizing or autocorrecting it and the browser from offering past entries.

```jsx
<TextArea label="Allowed claims" isIdentifier />
```

### Style Properties

These properties allow direct style application without using the `styles` prop:

- **Position:** `gridArea`, `order`, `gridColumn`, `gridRow`, `placeSelf`, `alignSelf`, `justifySelf`, `zIndex`, `margin`, `blockMargin`, `inlineMargin`, `inset`, `blockInset`, `inlineInset`, `position`, `scrollMargin`, `blockScrollMargin`, `inlineScrollMargin`, `scrollPadding`, `blockScrollPadding`, `inlineScrollPadding`
- **Dimension:** `width`, `height`, `blockSize`, `inlineSize`, `flexBasis`, `flexGrow`, `flexShrink`, `flex`

## Variants

### Sizes

- `small` - Compact size for dense interfaces
- `medium` - Standard size for most use cases
- `large` - Emphasized size for important text areas

## Properties

- **`autoSize`** `boolean` (default: `false`) — Whether the textarea should automatically resize based on content
- **`maxRows`** `number` (default: `10`) — Maximum number of visible rows when `autoSize` is enabled
- **`rows`** `number` (default: `3`) — Number of visible text rows
- **`value`** `string | null` — The text value in controlled mode. `null` clears the field and keeps it controlled
- **`defaultValue`** `string` — The default text value in uncontrolled mode
- **`isBuffered`** `boolean` (default: `true`) — Whether typed text is held locally until the controlled `value` catches up. This is what keeps the caret in place when the value round-trips through a store that re-renders a pass late; `onChange` still fires on every keystroke. Set to `false` for a caller that must see the field snap back to its own `value` the moment it declines a keystroke.
- **`placeholder`** `string` — Placeholder text when input is empty
- **`icon`** `ReactElement` — Icon element rendered before the input
- **`prefix`** `ReactNode` — Input decoration before the main input
- **`suffix`** `ReactNode` — Input decoration after the main input
- **`tooltip`** `string | TooltipProviderProps` — The input's own tooltip, opened on hover over the field box and on keyboard focus. A disabled input with a tooltip stays focusable, so the keyboard reaches it too. See [TextInput](./TextInput.md#with-a-tooltip) for the behaviour.
- **`suffixPosition`** `'before' | 'after'` (default: `'before'`) — Position of suffix relative to validation/loading state icons
- **`resize`** `string` — CSS resize value (e.g. `'vertical'`, `'none'`)
- **`size`** `'small' | 'medium' | 'large'` (default: `'medium'`) — Input size
- **`shape`** `'default' | 'plain'` (default: `default`) — Shape of the field box. `plain` is square with no border at rest, for a field set flush in a container that draws its edges, such as a toolbar or a panel header. Its border keeps its width and shows on focus and in a valid or invalid state, so nothing shifts
- **`autoComplete`** `string` — HTML [`autocomplete`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) token that tells the browser what to autofill (`street-address`, `off`, …). The lowercase `autocomplete` alias is deprecated.
- **`isIdentifier`** `boolean` (default: `false`) — Whether the field holds an identifier, such as a name, key, token or attribute name, rather than prose. Turns off the browser's text services: `autocapitalize="none"`, `autocorrect="off"`, `spellcheck="false"` and `autocomplete="off"`, so a phone keyboard neither starts the value with a capital nor rewrites it, and the browser offers no past entries. An explicit `autoComplete`, `autoCorrect` or `spellCheck` prop, or any of the four attributes in `inputProps`, still wins. iOS still offers contact AutoFill above the keyboard: no attribute turns that off
- **`ignorePasswordManagers`** `boolean` (default: `false`) — Whether password manager extensions should leave the field alone: for a secret that is not the user's own login, such as a private key. See [PasswordInput](./PasswordInput.md#a-secret-that-is-not-a-login)
- **`maxLength`** `number` — Maximum number of characters allowed
- **`minLength`** `number` — Minimum number of characters required
- **`inputProps`** `Props` — Direct HTML props passed to the inner textarea element, merged over the props React Aria generates: a key you set wins, and event handlers are chained rather than replaced. The explicit `isDisabled`, `maxLength`, `minLength`, `autoFocus` and `autoComplete` props win over the same attributes in `inputProps` when they are set; one left unset keeps the `inputProps` value. Set the row count with `rows`, which always applies
- **`wrapperProps`** `Props` — Additional HTML props passed to the input wrapper container
- **`inputRef`** `RefObject<HTMLTextAreaElement>` — Ref to the inner textarea element
- **`wrapperRef`** `RefObject<HTMLDivElement>` — Ref to the input wrapper container
- **`loadingIndicator`** `ReactNode` — Rendered in place of the default loading icon while `isLoading` is set
- **`validate`** `(value: string) => ValidationError | true | null | undefined` — Client-side validation. React Aria sets `aria-invalid` from the returned errors at once; the invalid style and the message follow after the user edits or leaves the field, so an empty field does not open in red. An explicit `errorMessage` replaces the returned message, and an explicit `isInvalid` (or a form's validation) takes over from `validate` entirely
- **`inputStyles`** `Styles` — Custom styles for the textarea element
- **`onChange`** `function` — Callback fired when the input value changes
- **`onBlur`** `function` — Callback fired when the input loses focus
- **`onFocus`** `function` — Callback fired when the input receives focus
- **`onKeyDown`** `(e: KeyboardEvent) => void` — Callback fired when a key is pressed in the textarea. See [Keyboard Events](#keyboard-events)
- **`onKeyUp`** `(e: KeyboardEvent) => void` — Callback fired when a key is released in the textarea

### Keyboard Events

`onKeyDown` and `onKeyUp` are attached to the `<textarea>` by React Aria's `useTextField`. TextArea has no key handling of its own, so the handler simply receives the event: `e.preventDefault()` cancels what the browser would do with the key, such as inserting a newline on `Enter`.

The handler receives React Aria's keyboard event rather than a plain React one, and once you pass `onKeyDown` React Aria stops the key's propagation after your handler: a parent's `onKeyDown` no longer sees it. Call `e.continuePropagation()` for the keys that should travel on.

`Escape` and `Tab` are the exception, as in every field: they go on to ancestors, so a surrounding `Dialog` still closes on `Escape` and moves focus on `Tab`. When your handler acts on one, call `e.preventDefault()` and it stays at the textarea:

```jsx
<TextArea
  label="Comment"
  onKeyDown={(e) => {
    if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
      e.preventDefault(); // no newline
      send();
    } else if (e.key === 'Escape' && isEditing) {
      e.preventDefault(); // keep a surrounding Dialog open
      cancelEdit();
    }
  }}
/>
```

The fields that do handle keys themselves (`ComboBox`, `SearchComboBox`, `TagInput`, `CommandTextArea`) run your `onKeyDown` first and skip their own handling for a key you prevent. `NumberInput` is the exception: React Aria runs its stepping and `Enter` commit before your handler. In all of them, a prevented `Escape` or `Tab` stays at the input.

### Base Properties

Supports [Base properties](../../BaseProperties.md)

### Field Properties

Supports all [Field properties](../../FieldProperties.md)

## Sub-elements

The TextArea component renders the following sub-elements that can be customized via the `styles` prop:

- **Prefix**: Content displayed before the input area
- **Suffix**: Content displayed after the input area
- **State**: Container for validation and loading indicators
- **InputIcon**: Icon displayed within the input

## Style Properties

The TextArea component supports all standard style properties:

`display`, `font`, `preset`, `hide`, `opacity`, `whiteSpace`, `gridArea`, `order`, `gridColumn`, `gridRow`, `placeSelf`, `alignSelf`, `justifySelf`, `zIndex`, `margin`, `inset`, `position`, `width`, `height`, `flexBasis`, `flexGrow`, `flexShrink`, `flex`, `reset`, `padding`, `paddingInline`, `paddingBlock`, `shadow`, `border`, `radius`, `overflow`, `scrollbar`, `outline`, `textAlign`, `color`, `fill`, `fade`, `textTransform`, `fontWeight`, `fontStyle`, `flow`, `placeItems`, `placeContent`, `alignItems`, `alignContent`, `justifyItems`, `justifyContent`, `align`, `justify`, `gap`, `columnGap`, `rowGap`, `gridColumns`, `gridRows`, `gridTemplate`, `gridAreas`

## Accessibility

The TextArea component follows WAI-ARIA guidelines:

- Uses semantic `textarea` HTML element
- Supports proper keyboard navigation and text selection
- Associates labels with the input element using `aria-labelledby`
- Provides clear focus indicators
- Announces validation states and error messages to screen readers
- Supports auto-completion and spell-checking

## Best Practices

- Use descriptive labels that clearly indicate the expected content
- Provide placeholder text for additional context when appropriate
- Set appropriate `rows` to indicate expected content length
- Use `autoSize` for dynamic content that may vary in length
- Consider `maxRows` to prevent excessive vertical growth
- Provide clear validation messages when input is invalid
- Use read-only state for displaying non-editable content
