refactor(useGridFocus): roving tabindex + handleFocus + isRtl; Calendar uses it#3489
Draft
cixzhang wants to merge 1 commit into
Draft
refactor(useGridFocus): roving tabindex + handleFocus + isRtl; Calendar uses it#3489cixzhang wants to merge 1 commit into
cixzhang wants to merge 1 commit into
Conversation
Bring useGridFocus to parity with useListFocus: opt into a hook-owned roving tab stop that stamps tabindex 0/-1 on the focusable cells' focus targets, repairs it on render, and moves it with arrow navigation. Returns a handleFocus for onFocus sync and gains isRtl to flip the horizontal arrows. Calendar now uses this instead of the separate useCalendarRovingTabindex hook: it seeds the initial tabbable day button (selected > today > first-enabled) and lets the grid hook own the tab stop thereafter.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
josephfarina
approved these changes
Jul 3, 2026
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
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
Brings
useGridFocusto API parity withuseListFocusby adding hook-owned roving-tabindex support, and migratesCalendarto use it instead of the separateuseCalendarRovingTabindexhook.Previously
useListFocuscould own a single tab stop across its items (hasRovingTabIndex: stampstabindex0/-1, repairs the stop on layout, moves it with navigation, and exposes ahandleFocusto re-sync), whileuseGridFocuscould only move focus — soCalendarneeded a bespokeuseCalendarRovingTabindexhook to decide which day button was tabbable and threadisTabbable(day.iso)into every cell. That split is no longer necessary.Changes
useGridFocushasRovingTabIndex?: boolean(defaultfalse). When enabled the hook owns a single tab stop: exactly one focusable cell's resolved focus target carriestabindex="0", the rest-1. Stamped/repaired on every commit via a layout effect (same shape asuseListFocus.syncTabStops) and moved with arrow/Home/End navigation. An existingtabindex="0"is honored, so the caller can seed which cell starts tabbable.getFocusTarget), not therole="gridcell"wrapper — so it works when the focusable element is a descendant of the cell (Calendar's day<button>).setAttribute('tabindex', …)(matchinguseListFocus), skipping redundant writes.handleFocusto attach to the container'sonFocus(no-op unless roving is on, always safe to attach).isRtl?: boolean(defaultfalse) that flipsArrowLeft/ArrowRight, same mechanism asuseListFocus.CalendarhasRovingTabIndex: true, destructureshandleFocus, and wires it on the grid container'sonFocus.useCalendarRovingTabindeximport/usage. The initial tab-stop seed (selected → today → first-enabled in-month day) is computed inline and rendered as each day button's initialtabIndex; the grid hook owns the stop thereafter.useCalendarRovingTabindex— left in place. It's a public export (@astryxdesign/core/hooksand the Calendar barrel), so removing it would be a breaking change; keeping it avoids that while Calendar no longer depends on it. Removal can be a follow-up.Tests
useGridFocus.test.tsxcovering seeding, repair, arrow-move-the-stop, RTL flip, and roving-off passthrough.@astryxdesign/coretypecheck (clean), eslint on changed files (clean), and Calendar +useGridFocus+ DateInput/DateRangeInput/DateTimeInput test suites (all pass).