Textarea
A labeled native textarea for multi-line text with helper text, validation feedback, and accessible descriptions.
Import Textarea
Import Textarea from Tavix:
import { Textarea } from "tavix";Component API
<Textarea
label
error
helperText
required={false}
{...props}
/>Props
label: Visible label associated with the textarea.error: Validation message. Takes precedence overhelperText.helperText: Supporting text shown below the textarea when there is noerror.required: Marks the textarea as required. Defaults tofalse....props: Additional native textarea attributes and event handlers, includingid,name,value,defaultValue,placeholder,rows,cols,maxLength,disabled,readOnly, and events.
Behavior
- Renders a native
<textarea>element for standard browser and form behavior. - Generates an accessible id when no
idis provided. - Associates the label with the textarea through
htmlForandid. - Adds
aria-requiredwhenrequiredistrue. - Adds
aria-invalidwhenerroris provided. - Links helper or error text through
aria-describedby. - Gives error text an
alertrole. - Displays
errorinstead ofhelperTextwhen both are provided. - Supports controlled and uncontrolled usage through native textarea props.
- Forwards native attributes and event handlers to the textarea.
Examples
Basic textarea
<Textarea label="Message" rows={4} placeholder="Write a message" />
<Textarea
label="Description"
rows={6}
placeholder="Describe your project"
/>Controlled textarea
const [notes, setNotes] = useState("");
<Textarea
label="Notes"
value={notes}
onChange={(event) => setNotes(event.target.value)}
helperText="Maximum 500 characters."
/>;Uncontrolled textarea
Use defaultValue when the component should manage its own value after an initial value:
<Textarea
label="Summary"
defaultValue="Initial summary"
rows={4}
onChange={(event) => {
console.log(event.target.value);
}}
/>;Required and helper text
<Textarea
label="Feedback"
required
helperText="Tell us what we can improve."
rows={5}
/>;Error, disabled, and read-only states
<Textarea
label="Message"
error="Message is required."
rows={4}
/>
<Textarea
label="Disabled message"
value="This message cannot be edited."
disabled
rows={4}
/>
<Textarea
label="Read-only notes"
value="These notes are read-only."
readOnly
rows={4}
/>;Character limit
Use native maxLength to limit the number of characters:
<Textarea
label="Bio"
rows={4}
maxLength={160}
helperText="Maximum 160 characters."
/>;Change events
Textarea change handlers receive the native input event. Read the current text from event.target.value:
<Textarea
label="Message"
onChange={(event) => {
setMessage(event.target.value);
}}
/>Accessibility
- Provide a clear
labelso the textarea has an accessible name. - The generated label connection uses
htmlForandid. - Use
requiredto communicate that text must be provided. - Use
errorto communicate validation feedback. - Helper and error text are linked to the textarea through
aria-describedby. - Use
rowsto provide an appropriate initial editing area.
Notes
- Textarea renders a native
<textarea>and preserves standard browser behavior. - Use
valuewithonChangefor controlled usage. - Use
defaultValuefor uncontrolled usage with an initial value. - Native props such as
rows,cols,maxLength,disabled, andreadOnlyare supported through...props. - When both
errorandhelperTextare provided, only the error message is displayed.