Form.Item error messages lack aria-describedby association
0 reputation · 24 Oct 2022, 08:25 UTC
0 reputation · 24 Oct 2022, 08:25 UTC
Ant Design's Form.Item renders validation error text beneath the input but does not add an aria-describedby attribute to the associated control.
The documentation states that developers must supply a help prop or set validateStatus="error" with custom help to achieve the required ARIA linkage, indicating the library intentionally avoids automatic association.
This gap persists in both the 4.x and 5.x release lines and has been discussed in the project repository without a consensus on adding built‑in binding.
Relying on the default rendering can cause screen readers to skip error announcements, violating WCAG 1.3.1 and 4.1.2.
help prop to guarantee announcement?help and error text are present?aria-describedby binding in future antd versions?35275 reputation · 24 Oct 2022, 10:20 UTC
In Ant Design 4.x and 5.x a Form.Item that fails validation renders an error div with role="alert", but the associated input never receives an aria-describedby attribute. This is intentional: the library expects developers to supply a help prop or to set validateStatus="error" with custom help text so that the ARIA linkage can be created automatically.
div rendered by Form.Item has no id attribute.help prop is provided, Ant Design generates a unique id for the help element and attaches it to the input via aria-describedby.help prop simultaneously can cause duplicate announcements.aria-describedby binding for the default error message.Ant Design prioritises a lightweight API: the default error rendering is meant for visual feedback only, and the library defers accessibility concerns to the developer. Requiring an explicit help prop keeps the component flexible for custom UI patterns and avoids hard‑coding IDs that might clash in complex forms.
<Form.Item help="Required field" rules={[{ required: true }]}>. Ant Design will automatically:
id for the help div.aria-describedby="" to the underlying input.validateStatus="error" and supply help yourself. Do not rely on the library’s default error text.
Form.Item, add a unique id and set aria-describedby on the input manually.
help prop or manual binding, focus the input or trigger validation and confirm the error message is announced.
Never use both the default error text and a help prop. If you need to display the error in two places (e.g., inline and in a summary), use help for the inline case and Form.ErrorList for the summary, ensuring each has a distinct id and is referenced only once by the input.
Current Ant Design documentation and GitHub discussions indicate that automatic aria-describedby for the default error message is not planned for upcoming releases. The recommended approach remains the explicit help prop or manual binding.
Do you use a custom component to render error messages (e.g., a separate ErrorText component) instead of Ant Design’s default error div? This detail may affect how you implement the ARIA linkage.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.