fix(core): restrict focusableSelector href matching to real links#3714
Open
bhamodi wants to merge 1 commit into
Open
fix(core): restrict focusableSelector href matching to real links#3714bhamodi wants to merge 1 commit into
bhamodi wants to merge 1 commit into
Conversation
|
@bhamodi is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
c150ee0 to
83cbb9f
Compare
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
FOCUSABLE_SELECTOR(packages/core/src/hooks/focusableSelector.ts:25) built the canonical focusable-elements selector with a bare[href]term. That matches any element carrying anhrefattribute — a<link>in the head, a<span href>, or a custom element — not just focusable links. Only<a href>and<area href>are actually focusable viahref.useFocusTrapfeeds this selector straight intoquerySelectorAllto compute trap boundaries (the first/last tab stop). A non-focusable element carryinghrefcould therefore be picked as the first or last "tab stop", breaking Tab-wrap inside a trap — the boundary element never receives focus, so the wrap condition never fires.This narrows the term to
a[href], area[href]. The rest of the selector is unchanged.Changes
packages/core/src/hooks/focusableSelector.ts:[href]→a[href], area[href]inFOCUSABLE_SELECTOR. The doc-comment describes this term as "link", which stays accurate.packages/core/src/hooks/useFocusTrap.test.tsx: added aFOCUSABLE_SELECTOR href matchingblock — asserts the selector matches<a href>/<area href>but excludes<span href>and<link href>, plus an end-to-end check thatfocusFirstlands on an<a href>inside a trap.Test plan
node_modules/.bin/vitest run --root . packages/core/src/hooks— 118 pass (12 files), including the 2 new tests.useFocusTrap.test.tsxnow has 8 tests (was 6). This is the only importer offocusableSelector, and its tests live in this directory.[href]and running the new test fails onexpect(matches).not.toContain(span), proving it catches the regression.tsc --project packages/core/tsconfig.json --noEmit— clean.eslinton both changed files — clean.Notes
Found during a broader a11y audit of core hooks. Scoped to this one selector fix — related findings (e.g. excluding
aria-disabledelements) are intentionally left out.