feat: WCAG (1.3.1) add FieldLegend component to address missing legend #1674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes (including videos or screenshots)
Adds a new
FieldLegendcomponent that renders a visually hidden<legend>to be used insideFieldGroupcomponents. This addresses the “missing legend” warning reported by WAVE and improves semantic structure in accordance with WCAG 1.3.1 – Info and Relationships.Uses @react-aria/visually-hidden to visually hide the legend while keeping it accessible to assistive technologies.
Ensures semantic correctness by preserving the required as a direct child of the
rendered by FieldGroup.Intended for use in FieldGroup components.
Issue(s)
Screenshots
Further comments
I've tried to hide the
<legend>element both visually and from screen readers to avoid redundancy and improve accessibility.I'm using
@react-aria/visually-hiddento hide the legend in a way that removes it from the visual flow and from screen reader output.This is important because the same text (
t('DummyText')) is already passed to<AccordionItem title={t('DummyText')}>, which provides both the visible label and the screen reader announcement. Including it again in a<legend>would result in redundant information for assistive technologies.The goal here is to preserve the semantic structure (keeping the
<legend>as part of the DOM) while avoiding duplicate announcements.From a WCAG perspective, this approach should be acceptable, since
FieldLegendis still a direct child ofFieldGroup(which renders a<fieldset>), and a<fieldset>requires a<legend>for semantic correctness.