-
Notifications
You must be signed in to change notification settings - Fork 184
fix: Ensure aria-hidden applies to shadow root #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that when aria-hidden="true"
is set on a <relative-time>
element, the attribute also applies inside its shadow root, hiding the rendered text from assistive technologies.
- Added
'aria-hidden'
to the element’sobservedAttributes
so attribute changes are handled. - Introduced a private
#updateRenderRootContent
method to wrap content in a hidden<span>
whenaria-hidden="true"
. - Added new tests to verify shadow-root behavior and updated the example page with a toggle button.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
test/relative-time.js | Added [aria-hidden] test suite to assert shadow-root behavior |
src/relative-time-element.ts | Observes aria-hidden and updates rendering via #updateRenderRootContent |
examples/index.html | Demo button toggling aria-hidden on <relative-time> |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch
Relates to: https://github.com/github/pull-requests/issues/17192
Problem
When
aria-hidden="true"
is set on an relative-time element, the attribute doesn't always persist into the shadow root. As a result, even whenaria-hidden
is applied, the text rendered in relative-time can end up composing the accessible name (instead of being hidden from the AT tree).Solution
This makes update to render the text content within
aria-hidden="true"
, whenaria-hidden="true"
is set on the shadow root.Demo
Before (no sound):
Before.mp4
video description: I'm on the demo page with the developer console open. The markup shows
aria-hidden
being toggled between true and false relative-time upon pressing the button. I switch to the accessibility tree mode. I see the accessible name for the button remains:With aria-hidden on Dec 31, 1969
despite toggling.After (no sound):
After.mp4
video description: I'm on the demo page with the developer console open. The markup shows
aria-hidden
being toggled between true and false relative-time upon pressing the button. I switch to the accessibility tree mode. I see the accessible name for the button toggle between:With aria-hidden on Dec 31, 1969
andWith aria-hidden
as we'd expect.