TextArea
This is a headless native text input with more than one line. It has a modality-aware focus state, the disabled and readonly booleans of React Aria Components, validation data attributes, and an optional automatic height.
Anatomy
TextArea has one part. The part makes a native <textarea> element. Each native textarea attribute goes directly to that element.
<script>
import { TextArea } from '@human-kit/ui';
</script>
<TextArea aria-label="Message" placeholder="Write your message..." required autoResize />States
The component shows the interaction state and the validation state in data-* attributes: data-focused, data-focus-visible, data-hovered, data-disabled, data-readonly, data-invalid, data-required, and data-autoresize. Thus you write all of the styles in plain CSS or in utility classes.
Automatic height
Set autoResize when the textarea must become larger with the content. Use minRows and maxRows to set the limits of the height. If you do not set autoResize, the native rows attribute and the manual resize control stay in operation.
Usage guidelines
- Put the native textarea props (
name,value,placeholder,rows,cols,maxlength, andwrap) directly onTextArea. - Use
disabled,readonly,invalid, andrequiredto control the validation state and the interaction state. The native behavior stays correct. - Set
autoResizewhen the textarea must become larger with the content. UseminRowsandmaxRowsto set the limits of the height. - Write the styles for the state with
data-focused,data-focus-visible,data-hovered,data-disabled,data-readonly,data-invalid,data-required, anddata-autoresize.
Accessibility
TextAreamakes a native<textarea>element, and it acceptsbind:value.data-focus-visibleobeys the shared modality contract. The component shows it only for a keyboard focus or a virtual focus.- The
invalidprop setsaria-invalid. Thereadonlyprop setsreadonlyandaria-readonly. Therequiredprop setsrequiredandaria-required. - The native textarea semantics already give the multiline textbox behavior. Thus you do not set
aria-multiline.
API reference
Root
The textarea control. It makes a native <textarea> element and puts each native attribute on it. It shows its state in data attributes.
* required. Native HTML attributes of the underlying element are also accepted.