Skip to main content

Textarea

A Textarea is a large text field users can type into. This pattern should be used when the expected user input is a long, multi-line text.

Example

Live Editor
Result
Loading...

Usage Rules

Do:

  • Use short and objective labels
  • Communicate that a Textarea is optional by including an "optional" info after the label
  • Make sure the user knows if a field is required by adding the required property.
  • Make the area big enough to accommodate most expected inputs
  • Validate input after users have finished interactions with the field and not before
  • Indicate in the error text what the problem is and how to fix it

Don’t:

  • Use a Textarea without a label
  • Use a Textarea for very short inputs (use an Input instead)
  • Add examples or complementary information to the label
  • Replace the label with an error message. Use the info text instead

Variants

Full width

You can make the Textarea width to 100% by using the fullWidth prop.

Live Editor
Result
Loading...

Custom Height

You can add custom Textarea height by using the height prop.

Live Editor
Result
Loading...

Label

Live Editor
Result
Loading...

You can add extra piece of information to the label by including a tooltip.

Live Editor
Result
Loading...

Disabled

Live Editor
Result
Loading...

Info Text

The info text is used for hints or validation messages.

warning

When on firefox, the input and infoText will take full width by default. If you need the input to have a fixed width and the infoText to wrap to a second line, please either add css={} prop, a wrapper element with a fixed width, or a fixed width to the <form> element.

Live Editor
Result
Loading...

You can change the position of the info text to be on top of the TextArea.

warning

Please avoid using the Info Text on top of the TextArea when you also need the optional label.

Live Editor
Result
Loading...

We also support text tags inside the Info Text. Like strong, b, i and a.

Live Editor
Result
Loading...

Disabled Textarea

Live Editor
Result
Loading...

Optional field

You can show the field as optional or custom text by using the optionalText prop as string.

Live Editor
Result
Loading...

onBlur event

Live Editor
Result
Loading...

Ref

Access to native textarea element by using ref.

Live Editor
Result
Loading...

Props

NameTypeDefault
disabled
Native HTML attribute: Link
boolean
css
Add custom styles to this component. Use with caution. Learn more here: Link
SupportedStyleAttributes
inputFieldCss
SupportedStyleAttributes
label
Visual Label for the textarea
string
aria-label
Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link
string
aria-labelledby
Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link
string
id
Native HTML attribute: Link . Internally, this component uses a random id. We use it to associate an input with a label element. As the random id might break snapshot tests it can be overridden by setting an explicit id.
string
onBlur
Native HTML callback: Link
FocusEventHandler<HTMLTextAreaElement>
required
Native HTML attribute: Link
boolean
readOnly
Native HTML attribute: Link
boolean
onChange
Native HTML callback: Link
ChangeEventHandler<HTMLTextAreaElement>
value
The textarea's value
string | number
name
Native HTML attribute: Link
string
placeholder
Native HTML attribute: Link
string
infoText
Instructions to help users correctly fill in the data
string
optionalText
optionalText value to show the field is optional with custom text
string
infoTextTop
positions the infoText on top of the Select
boolean
invalid
Visually notify the user that the provided value is invalid
boolean
minLength
Native HTML attribute: Link
number
maxLength
Native HTML attribute: Link
number
labelIconTooltip
The labelIconTooltip content can either be pure text or any rich content wrapped in a React component The labelIconTooltip content will be shown when hovering the label icon. The labelIconTooltip position is used to define the positioning of the tooltip When the labelIconTooltip content is not provided, the label icon will be not shown.
Omit<TooltipProps, "children">
height
String prop for height to accept % and px
string
rows
Native HTML attribute: Link
number
cols
Native HTML attribute: Link
number
fullWidth
Boolean prop to take 100% width
boolean
ref
Ref<HTMLTextAreaElement>
key
Key | null
data-{foo}
Data attributes can be used by testing libraries to retrieve components or assert their existence
string
* - the prop is required.