Textarea
Textarea component is a multi-line Input which allows you to write large texts.
Installation
npx nextui-cli@latest add input
The above command is for individual installation only. You may skip this step if @nextui-org/react is already installed globally.
Import
Usage
Disabled
Read Only
Required
If you pass the isRequired property to the input, it will have a danger asterisk at
the end of the label and the textarea will be required.
Clear Button
If you pass the isClearable property to the textarea, it will have a clear button at the
end of the textarea, it will be visible when the textarea has a value.
Autosize
Textarea grows automatically based on the content, but you can also set a min and max height to
it using the minRows and maxRows properties. It is based on react-textarea-autosize.
Without Autosize
In case you want to disable the autosize feature, you can use the disableAutosize property.
Variants
With Error Message
You can combine the isInvalid and errorMessage properties to show an invalid textarea.
Description
Controlled
You can use the value and onValueChange properties to control the input value.
Note: NextUI
Textareaalso supports native events likeonChange, useful for form libraries such as Formik and React Hook Form.
Slots
- base: Input wrapper, it handles alignment, placement, and general appearance.
- label: Label of the textarea, it is the one that is displayed above, inside or left of the textarea.
- inputWrapper: Wraps the
label(when it is inside) and theinnerWrapper. - input: The textarea input element.
- description: The description of the textarea.
- errorMessage: The error message of the textarea.
- headerWrapper: Wraps the
labeland theclearButton.
Data Attributes
Textarea has the following attributes on the base element:
- data-invalid:
When the textarea is invalid. Based on
isInvalidprop. - data-required:
When the textarea is required. Based on
isRequiredprop. - data-readonly:
When the textarea is readonly. Based on
isReadOnlyprop. - data-hover: When the textarea is being hovered. Based on useHover
- data-focus: When the textarea is being focused. Based on useFocusRing.
- data-focus-visible: When the textarea is being focused with the keyboard. Based on useFocusRing.
- data-disabled:
When the textarea is disabled. Based on
isDisabledprop.
Accessibility
- Built with a native
<input>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.
API
Textarea Props
| Prop | Type | Default |
children | | |
minRows | | "3" |
maxRows | | "8" |
cacheMeasurements | | false |
variant | | "flat" |
color | | "default" |
size | | "md" |
radius | | |
label | | |
value | | |
defaultValue | | |
placeholder | | |
startContent | | |
endContent | | |
description | | |
errorMessage | | |
validate | | |
validationBehavior | | "aria" |
labelPlacement | | "inside" |
fullWidth | | true |
isRequired | | false |
isReadOnly | | |
isDisabled | | false |
isClearable | | false |
isInvalid | | false |
validationState | | |
disableAutosize | | false |
disableAnimation | | false |
classNames | |
Input Events
| Prop | Type | Default |
onChange | | |
onValueChange | | |
onClear | | |
onHeightChange | |

