---
title: TextArea
---

import LibraryInfo from '@theme/LibraryInfo'
import { ExternalCodeBlock, Feedback, TokensTable, PropsTable } from '../../src/components'
import { TextArea } from '@telus-uds/components-web'
import { TextArea as BaseDocs } from 'docs/@telus-uds/components-base'
import AvailableOnBoth from '../../partials/_platform-considerations-both.mdx'

# TextArea

<LibraryInfo figmaLink="https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2F4zJn2Qn6uXOqPP1GVDipy6%2F%25F0%259F%258D%2580-Allium-Components%3Fnode-id%3D451%253A4936" />

```jsx live
<TextArea
  label="Label"
  hint="A usually much longer hint below"
  hintPosition="below"
  tooltip="Tooltip content"
/>
```

## Introduction

```jsx
import { TextArea } from '@telus-uds/components-web'
```

Use the `TextArea` component to collect long-form information such as product feedback or support queries.
The `TextArea` height will automatically increase when new lines are added - this behavior can be limited within the theme.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

### Controlled component

If it is required that the state of the `TextArea` be controlled by the application or other external methods,
`value` and `onChange` props must be passed to the `TextArea`.

<ExternalCodeBlock file="text-area-controlled" scope={{ TextArea }} />

If the `TextArea` value should not be changed by user input, a `readOnly` prop must be provided.

```jsx live
<TextArea label="Read only" readOnly value="won't change" />
```

### Uncontrolled component

If it is not necessary to control the `TextArea` state, you can create one without a value prop.
In this case its value can be accessed within the `onChange` callback.

### Getting feedback for entered values

Use the `feedback` prop to give the user feedback regarding their input (keep it as brief as possible).
You can affirm that the user's input was correct, or highlight errors that must be corrected by setting the
`validation` prop.

```jsx live
<TextArea label="Order instructions" initialValue="Leave at the main door" validation="success" />
```

```jsx live
<TextArea label="Order instructions" validation="error" feedback="This field must be filled." />
```

This component does not perform input validations, as that is an application level concern. You will need to track the
value of your form fields and perform any required data validations either client side or server side, depending on
the context.

### Supplying a hint

Use a `hint` to succinctly clarify attributes of the expected input data, such as the expected format, or an indicator
that the field is optional. It is a more usable and accessible option than the HTML `placeholder` attribute.

```jsx live
<TextArea label="Special requests" hint="Please include order number" />
```

- `hint` can be used beside the label (inline) or below
  - Label and inline hint text should not exceed 40 characters total, otherwise, use hint text below the label
- The `hint` should **not** be longer than 85 characters
- The `hint` should **not** wrap more than 3 lines on all viewport sizes
- Developers can use `hintPosition` to re-position the `hint` below the `label` if the text supplied to the inline
  `hint` wraps

### Using a tooltip

When a more in-depth explanation is needed to fill out a `TextArea` properly, additional instructions may be provided
to the `tooltip` prop.

```jsx live
<TextArea
  label="Describe your inquiry"
  hint="Please include customer ID"
  tooltip="Inquiries will be addressed by our staff ASAP. We will reach out if the query cannot be fulfilled. Please check your confirmation email for your customer ID."
/>
```

### Using a tooltip as an object

TextArea accepts tooltip props in two formats:

1. `tooltip` prop being a string
2. `tooltip` prop being an object (this is mapped and passed to `Tooltip`).

Please refer to the [Tooltip's Props](tooltip) to learn more.

```jsx live
<TextArea
  label="Describe your inquiry"
  hint="Please include customer ID"
  tooltip={{
    content:
      'Inquiries will be addressed by our staff ASAP. We will reach out if the query cannot be fulfilled. Please check your confirmation email for your customer ID.',
    activateOnHover: true
  }}
/>
```

### Using maxCharacterAllowed

`maxCharacterAllowed` defines the maximum number of characters allowed in the `TextInput` field.
If the user exceeds this limit, an error message will be displayed using the feedback component. This ensures that users
receive clear guidance on the character limit, promoting a more intuitive form interaction.

```jsx live
function maxCharacterAllowedAndHintAndTooltip() {
  const [value, setValue] = React.useState('')

  return (
    <TextArea
      label="Label"
      hint="A usually much longer hint below"
      hintPosition="below"
      tooltip="Tooltip content"
      maxCharacterAllowed={10}
      value={value}
      onChange={(filteredText) => setValue(filteredText)}
    />
  )
}
```

### Assigning an ID

The `TextArea` component provides the capability to specify a custom identifier through the use of the `nativeID` property.

```jsx live
<TextArea
  label="Label"
  nativeID="My custom id goes here"
  onClear={() => console.log('Back to square one')}
/>
```

:::info
In order to support more advanced usages all additional props will be passed down to the React Native's
`TextArea` component. See <a href="https://reactnative.dev/docs/textinput" target="_blank">React Native documentation</a> for
supported props and <a href="https://reactnative.dev/docs/textinput" target="_blank">React Native Web documentation</a> for
their implementation on the web.
:::

### Accessibility

`TextArea` is accessible to screen readers on both native platforms and Web. It will be announced with the `label` prop
if it is provided, and optionally described with the `hint`, `tooltip` and `feedback`.

### Platform considerations

<AvailableOnBoth />

:::info
Due to React Native's implementation of `TextInput` it's not possible to access the current value of the input by
passing a ref. You can only access it within the `onChange` callback.
:::

## Props

<PropsTable base={BaseDocs} />

## Tokens

<TokensTable base={BaseDocs} component="TextArea" />

## Variants

`TextArea` has no visual variants, but its appearance may change based on the `validation` and `inactive` props.

```jsx live
<TextArea label="Last name" validation="success" initialValue="Potter" />
```

```jsx live
<TextArea label="Last name" validation="error" />
```

```jsx live
<TextArea label="Inactive" inactive initialValue="can't touch this" />
```

## Feedback

<Feedback component="TextArea" />
