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
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.
Custom Height
You can add custom Textarea height by using the height
prop.
Label
You can add extra piece of information to the label by including a tooltip.
Disabled
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.
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.
We also support text tags inside the Info Text. Like strong
, b
, i
and a
.
Disabled Textarea
Optional field
You can show the field as optional or custom text by using the optionalText
prop as string.
onBlur event
Ref
Access to native textarea element by using ref.
Props
Name | Type | Default |
---|---|---|
disabled Native HTML attribute: Link |
| — |
css Add custom styles to this component. Use with caution. Learn more here: Link |
| — |
inputFieldCss |
| — |
label Visual Label for the textarea |
| — |
aria-label Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
aria-labelledby Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
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. |
| — |
onBlur Native HTML callback: Link |
| — |
required Native HTML attribute: Link |
| — |
readOnly Native HTML attribute: Link |
| — |
onChange Native HTML callback: Link |
| — |
value The textarea's value |
| — |
name Native HTML attribute: Link |
| — |
placeholder Native HTML attribute: Link |
| — |
infoText Instructions to help users correctly fill in the data |
| — |
optionalText optionalText value to show the field is optional with custom text |
| — |
infoTextTop positions the infoText on top of the Select |
| — |
invalid Visually notify the user that the provided value is invalid |
| — |
minLength Native HTML attribute: Link |
| — |
maxLength Native HTML attribute: Link |
| — |
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. |
| — |
height String prop for height to accept % and px |
| — |
rows Native HTML attribute: Link |
| — |
cols Native HTML attribute: Link |
| — |
fullWidth Boolean prop to take 100% width |
| — |
ref |
| — |
key |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |