Skip to content

fix: Ensure aria-hidden applies to shadow root - #315

Merged
khiga8 merged 10 commits into
mainfrom
kh-support-aria-hidden
May 7, 2025
Merged

fix: Ensure aria-hidden applies to shadow root#315
khiga8 merged 10 commits into
mainfrom
kh-support-aria-hidden

Conversation

@khiga8

@khiga8khiga8 commented May 7, 2025

Copy link
Copy Markdown
Contributor

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 when aria-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", when aria-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 and With aria-hidden as we'd expect.

@khiga8
khiga8 marked this pull request as ready for review May 7, 2025 16:57
CopilotAI review requested due to automatic review settings May 7, 2025 16:57
@khiga8
khiga8 requested a review from a team as a code ownerMay 7, 2025 16:57
@khiga8khiga8 changed the title Ensure aria-hidden applies to shadow rootfix: Ensure aria-hidden applies to shadow rootMay 7, 2025

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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’s observedAttributes so attribute changes are handled.
  • Introduced a private #updateRenderRootContent method to wrap content in a hidden <span> when aria-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.

FileDescription
test/relative-time.jsAdded [aria-hidden] test suite to assert shadow-root behavior
src/relative-time-element.tsObserves aria-hidden and updates rendering via #updateRenderRootContent
examples/index.htmlDemo button toggling aria-hidden on <relative-time>

Comment threadtest/relative-time.js Outdated
Comment threadtest/relative-time.js Outdated
Comment threadtest/relative-time.js Outdated
Comment threadtest/relative-time.js Outdated
khiga8and others added 4 commits May 7, 2025 13:00
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>

@JoyceZhuJoyceZhu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀

@jonrohanjonrohan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@khiga8@jonrohan@JoyceZhu