TextArea
TextArea is a multiline TextField: 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.
import { TextArea } from 'patine-ui';
<TextArea label="Bio" placeholder="A few words about you" value={bio} onValueChange={setBio} maxLength={160} showCount maxRows={6} />
Try the props
minRowsmaxRowserror<TextArea
label="Bio"
placeholder="A few words about you"
maxLength={160}
value={bio}
onValueChange={setBio}
showCount
/>
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.
<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.
<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.
<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-labelledbyon the web);required,error(aria-invalid, read as the hint) anddisabledare announced, as on TextField. - 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 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: one line, with password and clear buttons