Repository navigation
fix(core): auto-detect RTL for arrow-key navigation in focus hooks - #4350
Merged
Merged
Conversation
bhamodi
requested review from
cixzhang,
ejhammond and
imdreamrunner
as code owners
July 26, 2026 04:22
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis ReportNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | View full report |
cixzhang
reviewed
Jul 27, 2026
| if (!el || typeof window === 'undefined') { | ||
| return false; | ||
| } | ||
| return window.getComputedStyle(el).direction === 'rtl'; |
Contributor
There was a problem hiding this comment.
Compute style here, but since we only use this in callbacks, it's likely okay.
cixzhang
approved these changes
Jul 27, 2026
cixzhang
enabled auto-merge (squash)
July 27, 2026 23:32
2 tasks done
This branch was successfully deployed
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
Fixes a11y scan finding #3 (WCAG 1.3.2, meaningful sequence / directionality):
useListFocusanduseGridFocusalready implement anisRtloption that swaps ArrowLeft/ArrowRight for horizontal navigation — but no component ever passes it, and there is no direction source (InternationalizationContextcarries locale only). So menus, toolbars, tab strips, SegmentedControl, Pagination, and the Calendar date grid never flip arrow direction in RTL locales: pressing ArrowRight in adir="rtl"toolbar moves focus visually left.The fix makes the hooks resolve direction themselves when
isRtlis not explicitly passed, by readinggetComputedStyle(container).direction === 'rtl'from the container element each hook already tracks via its ref. This is the same precedentResizable'sResizeHandlealready uses for RTL drag deltas (getRTLMultiplier). Every consumer of the two hooks gets correct RTL arrow-key navigation for free, with zero component changes.Design notes:
getComputedStyleruns only on keydown, and only when the pressed key is ArrowLeft/ArrowRight (and, for lists, only for horizontal orientations) — no reads on render, no layout thrash on unrelated keys.falsewhen there is no element or nowindow.isRtlstill wins: the option is nowboolean | undefined; an explicit boolean short-circuits detection (isRtl ?? isRtlElement(el)).useTreeFocuswas checked and has no latentisRtloption (tree expand/collapse semantics are a separate concern), so it is untouched.Changes
packages/core/src/hooks/isRtlElement.ts(new): shared internalisRtlElement(el)helper — SSR-safe computed-direction check.packages/core/src/hooks/useListFocus.ts:isRtldefault changed fromfalseto auto-detect from the list container; resolved lazily on horizontal arrow keydown. JSDoc/file header updated.packages/core/src/hooks/useGridFocus.ts: same auto-detection for the grid container's ArrowLeft/ArrowRight swap. JSDoc/file header updated.packages/core/src/hooks/useListFocus.doc.mjs,useGridFocus.doc.mjs:isRtlprop docs/defaults updated (targeted edits only).packages/core/src/hooks/useListFocus.test.tsx: new "RTL auto-detection (WCAG 1.3.2)" suite — 5 tests coveringdir="rtl"auto-detect (ArrowLeft = next, ArrowRight = previous), LTR default, and explicitisRtloverride in both directions.packages/core/src/hooks/useGridFocus.test.tsx: new suite — 4 tests coveringdir="rtl"auto-detect both directions, vertical keys unaffected, and explicitisRtl={false}override. Grid test helper gained adirprop on the container..changeset/a11y-rtl-arrow-keys.md: patch changeset.jsdom note: jsdom reflects the
dirattribute into computeddirectiononly on the element that carries it (verified), so tests setdir="rtl"on the container element the hooks read — nogetComputedStylemocking needed.Test plan
Tests 4 failed | 36 passed (40)across the two files); the explicit-isRtland LTR tests pass, pinning back-compat.node_modules/.bin/vitest run packages/core/src/hooks --reporter=dot— 14 files, 185 tests passed (9 new RTL tests included).node_modules/.bin/vitest run packages/core --reporter=dot— 5166 passed, 1 failed: the knownCalendar.test.tsx:884"February 2026" flake (duplicate text via the aria-live month announcement; click-based, not arrow-key). Passes deterministically in isolation and on file rerun (63 passed (63)); unrelated to this change.tsc --project packages/core/tsconfig.json --noEmit— clean.eslinton all changed files — 0 errors (doc.mjs files are eslint-ignored by repo config).prettier --check— all changed ts/tsx/md files clean. The two.doc.mjsfiles already fail prettier at HEAD (repo only formats*.{ts,tsx,md}per lint-staged); left unformatted per repo convention.node scripts/check-changesets.mjs— 45 changeset(s) valid.Notes