# React Native Text Area

> An accessible React Native multiline text input for iOS, Android and the web that grows as you type between minRows and maxRows, with a character count, label, helper text and error. Looks like the picker fields in every design, zero native code.

# TextArea

`TextArea` is a multiline [`TextField`](./text-field): a comment, a bio or a message. It starts at `minRows` lines and grows with the text up to `maxRows`, then scrolls. `showCount` counts the characters, out of `maxLength`.

```tsx
import { TextArea } from 'patine-ui';
```

```tsx live
import { useState } from 'react';
import { TextArea } from 'patine-ui';

export default function Example() {
  const [bio, setBio] = useState('');
  return (
    <TextArea
      label="Bio"
      placeholder="A few words about you"
      value={bio}
      onValueChange={setBio}
      maxLength={160}
      showCount
      maxRows={6}
    />
  );
}
```

## Example: write a review

A product review form: the field grows as you write up to eight lines, counts toward its limit, and only says it's too short after you try to post.

```tsx live
import { useState } from 'react';
import { Box, Button, Rating, Text, TextArea } from 'patine-ui';

export default function Example() {
  const [stars, setStars] = useState(4);
  const [text, setText] = useState('');
  const [tried, setTried] = useState(false);
  const [posted, setPosted] = useState(false);
  const short = text.trim().length < 30;
  if (posted) return <Text>Thanks! Your review shows after a quick check, usually within the hour.</Text>;
  return (
    <Box border radius="lg" padding="lg" gap="md" style={{ width: '100%', maxWidth: 440 }}>
      <Text weight="semibold">Review the Linen shirt</Text>
      <Rating value={stars} onValueChange={setStars} accessibilityLabel="Your rating" />
      <TextArea
        label="Your review"
        placeholder="How does it fit? How did it wash?"
        value={text}
        onValueChange={setText}
        minRows={3}
        maxRows={8}
        maxLength={600}
        showCount
        helperText="Others see your first name and city."
        error={tried && short ? `Write at least 30 characters (${30 - text.trim().length} to go)` : undefined}
      />
      <Button
        onPress={() => {
          setTried(true);
          if (!short) setPosted(true);
        }}
      >
        Post review
      </Button>
    </Box>
  );
}
```

## Height

The field starts at `minRows` lines (3 by default) and grows as the text wraps or the user adds lines. With `maxRows` it stops there and scrolls; without it, it keeps growing. `rows` fixes the height at that many lines.

```tsx live
import { View } from 'react-native';
import { TextArea } from 'patine-ui';

export default function Example() {
  return (
    <View style={{ gap: 16 }}>
      <TextArea label="Grows from 2 to 5 lines" minRows={2} maxRows={5} />
      <TextArea label="Always 4 lines" rows={4} />
    </View>
  );
}
```

On the web, a TextArea grows with its text but doesn't shrink back when text is deleted.

## Errors and helper text

As on every field, `error` turns the outline red and shows its message under the field, in place of `helperText`, beside the count.

```tsx live
import { useState } from 'react';
import { TextArea } from 'patine-ui';

export default function Example() {
  const [text, setText] = useState('Too short');
  return (
    <TextArea
      label="Feedback"
      required
      value={text}
      onValueChange={setText}
      helperText="What could we do better?"
      error={text.length < 20 ? 'Write at least 20 characters' : undefined}
      maxLength={500}
      showCount
    />
  );
}
```

## Accessibility

- The label names the field for screen readers on every platform (`aria-labelledby` on the web); `required`, `error` (`aria-invalid`, read as the hint) and `disabled` are announced, as on [TextField](./text-field#accessibility).
- At least 44pt tall, with the border in the primary color on focus, and a ring in the Patine and web designs.
- In Material the label stays raised on the border, as it does on Material's multiline fields.

## Props

TextArea takes every [TextField prop](./text-field#api) except `secureTextEntry` and `passwordToggle`, React Native's `TextInput` props, and these:

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `minRows` | `number` | `3` | The height it starts at, in lines. |
| `maxRows` | `number` | no limit | It grows up to this many lines, then scrolls. |
| `rows` | `number` | — | A fixed height of this many lines; sets `minRows` and `maxRows` both. |
| `maxLength` | `number` | — | The most characters it takes; the count shows it. |
| `showCount` | `boolean` | `false` | The character count under the field. |

## Related

- [TextField](./text-field): one line, with password and clear buttons
