Connect field metadata to a native textarea
Rendering a Conform field
Conform · Function
getTextareaProps generates props for an accessible native textarea from Conform field metadata. Options customize defaultValue and ARIA attributes.
Call getTextareaProps with field metadata and spread the returned object onto a native textarea. It supplies the field wiring and accessibility attributes; options can control defaultValue handling and ARIA behavior.
getTextareaProps(meta, options)| Name | Type | Description |
|---|---|---|
meta | FieldMetadata | Field metadata for the textarea, such as fields.content. |
options | GetTextareaPropsOptions | Optional settings controlling value and ARIA props, including value, ariaAttributes, ariaInvalid, and ariaDescribedBy. |
An object of props to spread onto a native textarea element.
import { getTextareaProps, useForm } from '@conform-to/react';
export function Example() {
const [form, fields] = useForm();
return (
<form {...form}>
<textarea {...getTextareaProps(fields.content)} />
</form>
);
}Spreads the helper-generated accessibility and field props onto a native textarea.
Rendering a Conform field
Controlled React state
Accessible validation feedback
Descriptive help text
getTextareaProps(meta, options) returns props for an accessible native textarea. The result can be spread directly onto the element, as in <textarea {...getTextareaProps(fields.content)} />.
Follow-up: How would you avoid uncontrolled initialization for a controlled textarea? Pass the value option as false so defaultValue is omitted.
By default, the helper includes aria-invalid and aria-describedby. The ariaInvalid option chooses whether those attributes use meta.errors or meta.allErrors, and the default is errors.
Follow-up: How can a description ID be included in aria-describedby? Supply it through ariaDescribedBy, commonly using meta.descriptionId.
The helper is optional convenience API for reducing boilerplate. Field metadata can also be used directly to assign the textarea props.
Follow-up: What should you do for a custom textarea component? Build a component-specific helper because this helper targets native textarea elements.
useFormgetFormPropsgetInputPropsgetSelectProps