fix(a11y): tabindex on <main> so the skip link moves focus reliably (WCAG 2.4.1)#3451
Open
bilal-karim wants to merge 1 commit into
Open
fix(a11y): tabindex on <main> so the skip link moves focus reliably (WCAG 2.4.1)#3451bilal-karim wants to merge 1 commit into
bilal-karim wants to merge 1 commit into
Conversation
…WCAG 2.4.1) The SkipNavigation primitive renders <a href="#content">, which targets <main id="content"> in main-content-container.svelte. By HTML spec, <main> without tabindex is not programmatically focusable -- so activating the skip link only reliably moves focus on Chromium-based browsers (Chrome, Edge). Safari and older Firefox scroll the target into view but leave focus on the skip link itself, defeating the bypass for keyboard and screen- reader users. Adding tabindex="-1" makes <main> programmatically focusable (so the hash-link navigation lands focus there) while keeping it out of the natural Tab order. Closes WCAG 2.4.1 sufficient- technique G1's "programmatically moves focus" requirement across all browsers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
One-attribute change: add
tabindex=\"-1\"to<main id=\"content\">inmain-content-container.svelteso the skip-navigation link reliably moves focus across browsers.The defect
SkipNavigation(src/lib/components/skip-nav.svelte) renders<a href=\"#content\">. Activating it should both visually scroll the target into view AND programmatically move focus to it. By HTML spec, a<main>withouttabindexis not focusable — so:In affected browsers, the skip link looks like it works (page scrolls) but the user's next Tab cycles right back through the nav chrome — defeating the bypass for keyboard and screen-reader users.
The fix
tabindex=\"-1\":<main>programmatically focusable so the hash-link navigation lands focus thereCloses WCAG 2.4.1 sufficient-technique G1's "programmatically moves focus" requirement.
Audit context
audit-output/issues/2.4.1-skip-link-target-focus.md.Test plan
Functional impact
Pure attribute addition.
tabindex=\"-1\"does not place<main>in the natural Tab order, so:<a href=\"#content\">,focus(), etc.) gains a targetNo risk to existing behavior.
🤖 Generated with Claude Code
A11y-Audit-Ref: 2.4.1-skip-link-target-focus