-
Notifications
You must be signed in to change notification settings - Fork 0
misc: d8-2641 #375
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
base: 3.0.x
Are you sure you want to change the base?
misc: d8-2641 #375
Conversation
Adding accessibility screenreader js to global.js
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
Adds JavaScript to improve accessibility for in-page anchor link navigation by moving focus to the target element after clicking an internal #... link.
Changes:
- Adds a global
DOMContentLoadedhandler that finds internal hash links and adds click listeners. - On click, focuses the target element (temporarily applying
tabindex="-1"and then removing it).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
modules/access_misc/js/global.js
Outdated
| if (target) { | ||
| // Temporarily make the element focusable | ||
| target.setAttribute('tabindex', '-1'); | ||
|
|
||
| // Move focus to the target without scrolling the page | ||
| target.focus({ preventScroll: true }); | ||
|
|
||
| // Optional: remove tabindex after a short delay | ||
| setTimeout(() => { | ||
| target.removeAttribute('tabindex'); | ||
| }, 1000); // 1 second delay is enough for screen reader to announce | ||
| } | ||
| }); | ||
|
|
Copilot
AI
Jan 22, 2026
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.
The click handler always calls target.setAttribute('tabindex', '-1') and later unconditionally removes the tabindex attribute. If the target element already had a tabindex (or an intentionally empty one), this will remove it and change keyboard navigation semantics. Please preserve and restore the previous tabindex value (or only remove it if it was added by this handler).
| if (target) { | |
| // Temporarily make the element focusable | |
| target.setAttribute('tabindex', '-1'); | |
| // Move focus to the target without scrolling the page | |
| target.focus({ preventScroll: true }); | |
| // Optional: remove tabindex after a short delay | |
| setTimeout(() => { | |
| target.removeAttribute('tabindex'); | |
| }, 1000); // 1 second delay is enough for screen reader to announce | |
| } | |
| }); | |
| if (target) { | |
| // Store existing tabindex state, if any. | |
| const hadTabIndex = target.hasAttribute('tabindex'); | |
| const previousTabIndex = target.getAttribute('tabindex'); | |
| // Temporarily make the element focusable if needed. | |
| if (!hadTabIndex) { | |
| target.setAttribute('tabindex', '-1'); | |
| } | |
| // Move focus to the target without scrolling the page | |
| target.focus({ preventScroll: true }); | |
| // Optional: restore or remove tabindex after a short delay | |
| setTimeout(() => { | |
| if (!hadTabIndex) { | |
| // We added tabindex, so remove it again. | |
| target.removeAttribute('tabindex'); | |
| } else if (previousTabIndex !== null) { | |
| // Element had a tabindex; restore its original value (including empty). | |
| target.setAttribute('tabindex', previousTabIndex); | |
| } | |
| }, 1000); // 1 second delay is enough for screen reader to announce | |
| } | |
| }); |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Describe context / purpose for this PR
Add JS for Anchor Link menu Accessibility
Issue link
https://cyberteamportal.atlassian.net/browse/D8-2641
Any other related PRs?
Link to MultiDev instance
http://md-2641-accessmatch.pantheonsite.io
Checklist for PR author