Skip to content

Conversation

@PeterYangIO
Copy link
Contributor

The required asterisk needs the aria-hidden="true" attribute so that it doesn't get announced by screen readers.

I discovered this issue since switching my input components to <InputField/> caused testing-library's getByLabelText to fail. That selector uses the accessibility tree (as pictured in screenshots) and looks for exact name matches, so getByLabelText("Name") would fail as the name would be "Name *" and not "Name".

I also fixed the broken InputField source link in the docs.

Screenshots

Before, asterisk was included in name property:
image

After, asterisk is no longer included in name property but still displays properly:
image

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari -> Unable to since I'm on Windows
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@PeterYangIO PeterYangIO requested review from a team and jfuchs January 5, 2022 04:20
@changeset-bot
Copy link

changeset-bot bot commented Jan 5, 2022

🦋 Changeset detected

Latest commit: 837984b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

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

@PeterYangIO PeterYangIO changed the title Add aria-hidden to InputLabel Add aria-hidden to InputLabel required asterisk Jan 5, 2022
@siddharthkp siddharthkp requested review from mperrotti and removed request for jfuchs January 5, 2022 09:56
Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great spot! Thank for taking the time to create a PR :)

@siddharthkp siddharthkp added accessibility bug Something isn't working react labels Jan 5, 2022
@siddharthkp siddharthkp self-assigned this Jan 5, 2022
@siddharthkp siddharthkp merged commit 39a3bc2 into primer:main Jan 5, 2022
@primer-css primer-css mentioned this pull request Jan 5, 2022
@PeterYangIO PeterYangIO deleted the users/peteryangio/label-aria-hidden branch January 5, 2022 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility bug Something isn't working react

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants