The Text Area component is a complete form control including a label, textarea, and help text.
Text Area uses similar functionality to Text Input but supports resize mode and a few native
props that inputs
don't support.
Features
Text Area is automatically connected to handle Accessibility features such as label, description and error message props.
- Built with a native
<textarea>element - Visual and ARIA labeling support
- Change, clipboard, composition, selection, and input event support
- Required and invalid states exposed to assistive technology via ARIA
- Support for description and error message help text linked to the input via ARIA
Usage
import { TextArea } from '@console/nimbus-ui/core';Examples
With Label
The label prop can be used to generate a label for the input.
This props sets the htmlFor attribute to a random generated id.
You are able to overwrite the this attribute if you need to take control of the htmlFor prop.
Full Width
The fullWidth prop can be used to make the text input full width.
With Hint
The hint prop can be used to create a prop for the description of the input.
This props sets the aria-describedby attribute to a random generated id.
The hint appears below the input.
Disabled
Required
Read Only
Invalid
Uncontrolled
TextArea can be used in an uncontrolled way by utilising the <form/> html component.
The following form will automatically submit using the url params. If you press "submit"
you can see the params in the URL change based on the off/on state of the input.
Auto Focus
The autoFocus prop is an attribute for indicating that an element should be focused on page load,
or when the element appears on the DOM. Refresh the page to trigger autoFocus.
Resize
The resize prop can be used to change the resize mode of the text area.
This props allows you to switch between vertical | horizontal | both | none, allowing the user to only resize the text area is the direction specified.
API
| Prop | Type | Default | Description |
|---|---|---|---|
| autoFocus | boolean | false | Whether the element should receive focus on render. @extends jsdoc from AriaTextFieldProps[autoFocus] |
| classes | { root?: string; label?: string; textarea?: string; hint?: string; error?: string; } | — | |
| data-testid | string | — | Data attribute for E2E testing purposes |
| disabled | boolean | false | Whether the input is disabled. |
| fullWidth | boolean | — | Whether the input is full width |
| hint | ReactNode | — | A description for the field. Provides a hint such as specific requirements for what to choose. @extends jsdoc from AriaTextFieldProps[description] |
| inputProps | InputHTMLAttributes<HTMLTextAreaElement> | — | HTML attributes to pass to the underlying input element |
| invalid | boolean | false | Whether the input is invalid |
| labelProps | LabelHTMLAttributes<HTMLLabelElement> | — | HTML attributes to pass to the underlying label element |
| readonly | boolean | false | Whether the input can be selected but not changed by the user. |
| required | boolean | false | Whether user input is required on the input before form submission. Often paired with the `necessityIndicator` prop to add a visual indicator to the input. |
| resize | enum | vertical | Resize mode for the Text Area |
| value | string | — | Use React.useState to control this prop. Needs to be used with an event handler such as `onChange`. The current value (controlled). @extends jsdoc from AriaTextFieldProps[value] |
React Aria
Figma