Skip to main content

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';
Loading…
<TextArea
  label="Bio"
  placeholder="A few words about you"
  value={bio}
  onValueChange={setBio}
  maxLength={160}
  showCount
  maxRows={6}
/>

Try the props​

Props
minRows
maxRows
error
<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.

Loading…
<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.

Loading…
<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.

Loading…
<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.
  • 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:

PropTypeDefaultDescription
minRowsnumber3The height it starts at, in lines.
maxRowsnumberno limitIt grows up to this many lines, then scrolls.
rowsnumber—A fixed height of this many lines; sets minRows and maxRows both.
maxLengthnumber—The most characters it takes; the count shows it.
showCountbooleanfalseThe character count under the field.
  • TextField: one line, with password and clear buttons