fix(FormLabel): hide visual necessity indicator from screen readers to prevent double announcement#3366
Open
starboyvarun wants to merge 1 commit intorazorpay:masterfrom
Conversation
The label rendered both a VisuallyHidden node ("required"/"optional" text
for screen readers) and a visible indicator (* or (optional)) without
hiding the visible one from AT. Screen readers announced both, e.g.
"required asterisk" instead of just "required".
Wrapping the visible necessityLabel in makeAccessible({ hidden: true })
emits aria-hidden on web and accessibilityElementsHidden /
importantForAccessibility on React Native, resolving the double
announcement without any visual change.
🦋 Changeset detectedLatest commit: 9bc10c5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
✅ PR title follows Conventional Commits specification. |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9bc10c5:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
FormLabelrenders two things whennecessityIndicatorisrequiredoroptional:VisuallyHiddennode — invisible to sighted users, read aloud by screen readers (e.g. "required" or "optional")*for required,(optional)for optional — which is also read by screen readersThe result is a double announcement. For example, NVDA/VoiceOver reads "Email required asterisk" instead of "Email required". The
(optional)case announces "Email optional open paren optional close paren".The TODO comment at FormLabel.tsx:155 acknowledged this:
Fix
Wrap the visible
necessityLabelinmakeAccessible({ hidden: true }). This emits:aria-hidden="true"on the wrapper elementaccessibilityElementsHidden={true}+importantForAccessibility="no-hide-descendants"makeAccessibleis already used by other Form components (SelectorGroupField,SelectorInput) — this follows the same pattern.No visual change. The
*and(optional)text continue to render as before — they are now just skipped by assistive technology since theVisuallyHiddennode already announces the information semantically.Testing
necessityIndicator="none"(default): no change —necessityLabelis null so the wrapper is not rendered