Accessible form setup
Applying Conform form metadata to a native HTML form in a React component.
Conform · Function
getFormProps returns the props needed to make a native form element accessible. It reduces repetitive prop wiring and supports options for controlling generated ARIA attributes.
Call getFormProps with the form metadata returned by useForm and spread the resulting object onto a native form element. Options let you control generated ARIA attributes and append an additional described-by identifier; the helper reduces boilerplate but is optional.
getFormProps(form, options)| Name | Type | Description |
|---|---|---|
form | FormMetadata | Form metadata returned by useForm. |
options | GetFormPropsOptions | Optional settings controlling generated ARIA attributes, including ariaAttributes, ariaInvalid, and ariaDescribedBy. |
An object containing the props required for an accessible native form element.
import { getFormProps, useForm } from '@conform-to/react';
export function Example() {
const [form] = useForm();
return <form {...getFormProps(form)} />;
}The helper supplies the accessibility-related props for a native form element.
Applying Conform form metadata to a native HTML form in a React component.
Adding a field or form description identifier to aria-describedby.
Choosing whether ARIA state uses errors or allErrors.
getFormProps returns the props needed to make a form element accessible. It is typically called with the form metadata from useForm and spread onto the native form element.
Follow-up: How would you use it with a custom component? The page recommends making a custom helper because this helper targets native form elements.
The standard usage is getFormProps(form), where form is the first value returned by useForm. The returned props are applied with JSX spread syntax.
Follow-up: What is the alternative if you do not want the helper? Read the form metadata directly and assign the required form props yourself.
The ariaAttributes option controls whether aria-describedby is included in the returned props, and it defaults to true. ariaInvalid controls whether ARIA state is based on meta.errors or meta.allErrors, while ariaDescribedBy appends an extra identifier.
Follow-up: Where can an extra description identifier come from? The documentation specifically mentions passing meta.descriptionId.
useFormgetFieldsetPropsgetInputPropsgetSelectPropsgetTextareaPropsgetCollectionProps