Textarea for notes, descriptions, and other multiline values. It integrates with Field for labels and validation.
Usage
Uncontrolled state
UsedefaultValue to set the initial notes. The textarea owns subsequent changes.
rows, maxLength, required, and readOnly are available. size accepts sm or md and defaults to md.
Visual choices
Compare the two sizes in default, focused, invalid, and disabled states. Automatic resizing is demonstrated separately below.Controlled state
Passvalue and update it with onValueChange to own the same notes in React state. The callback receives the next string value and event details; native onChange is also available.
Automatic resizing
Automatic resizing works in either state mode. This example also uses the controlled value for a character count.autoResize measures the committed value after controlled updates and measures uncontrolled edits directly. Rejected controlled edits do not change the height. It also updates after native form resets, rows, size, maxRows, and available width changes. Use maxRows to cap growth and scroll longer content.
Automatic sizing owns inline blockSize while enabled. Turning it off restores the current style.blockSize, or clears the automatic size if none is supplied. With automatic sizing off, rows and native styles control height. Manual resizing is disabled by default; set style={{ resize: 'vertical' }} when callers should resize the control themselves.
Native control and render composition
Native textarea attributes and handlers,className, style, and ref target the textarea. The ref receives an HTMLTextAreaElement. render accepts a textarea element or a callback receiving native textarea props and Field state. Forward the supplied props and ref to the native textarea so labels, validation, events, and automatic measurement keep working. Add a separate layout element when wrapper customization is needed.
onChange receives a React change event for the native textarea. onValueChange(value, details) retains the Base UI signature, including the native event, reason, cancel, and allowPropagation. The native event targets the textarea. Canceling the details preserves Base UI’s validation policy; it does not undo the native value. Controlled callers choose the committed value.
Native name, form, required, readOnly, disabled, submission, and reset behavior remain available. Field supplies label, description, name, and validation association. Enter inserts a line break in the textarea.
Props
The reference is generated from the public component types. Native attributes, including accessible names and event handlers, are also accepted on parts that render elements.boolean
default:"false"
Measures committed controlled values or uncontrolled edits, form resets, row and size changes, and width changes. Overrides blockSize while enabled.
string | ((state: InputState) => string | undefined)
CSS class applied to the textarea, or a function that returns a class
based on the input state.
number
Caps automatic height growth. Content beyond this row limit scrolls.
((value: string, eventDetails: { reason: "none"; event: Event; cancel: () => void; allowPropagation: () => void; isCanceled: boolean; isPropagationAllowed: boolean; trigger: Element | undefined; }) => void)
Receives the next string value and Base UI details, including the native event, reason and cancellation methods.
Ref<HTMLTextAreaElement>
Ref to the native textarea element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, InputState>
Composes the native textarea with a custom element or callback receiving textarea props and Field state. Forward the supplied props and ref to a textarea.
"md" | "sm"
default:"md"
Visual size of the textarea.