fix(status): clamp heatmap keyboard focus when the matrix shrinks#1474
Conversation
Derive the effective roving-tabindex cell at render time with Math.min against the current rows/cols, so exactly one gridcell keeps tabIndex=0 after a data refresh shrinks the matrix. Adds a regression test covering the shrink and arrow-key navigation from the clamped cell. Fixes #1443 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UZEaYdKFXuQw2Hf6XpPdEV
There was a problem hiding this comment.
Code Review
This pull request fixes a regression (#1443) where shrinking the heatmap matrix could cause the active cell in the roving tabindex state to go out of bounds, leaving the grid without any cell having tabIndex=0 and removing it from the tab order. This is resolved by clamping the active row and column indices to the current matrix dimensions during render. A corresponding unit test has been added to verify this behavior. I have no feedback to provide.
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
kriszyp
left a comment
There was a problem hiding this comment.
Nice, clean a11y fix. The render-time clamp is correct: Math.min(active[0], rows.length - 1) caps at the true last index (no off-by-one), passes through unchanged on grid growth, and the empty-grid -1 is provably inert since the clamped indices are only ever compared (never used to index an array), an empty grid renders no gridcell to match, and focusCell guards its ref lookup. Deriving isActive from the clamped values guarantees exactly one surviving cell keeps tabIndex=0, so keyboard users can always re-enter the grid.
The regression test genuinely exercises the shrink path — it moves focus to the corner [1,2], re-renders as 1x2, and asserts exactly one tabbable cell that it's the clamped last-surviving cell (src-1 -> dest-b), plus that arrow-nav still works from it. Verifies direction, not just non-crash.
One non-blocking suggestion: Math.max(0, Math.min(...)) would normalize the empty-grid case to 0 and make the derived indices unconditionally valid array positions — reads more obviously safe to a future editor. Purely optional; the current -1 is safe as written.
LGTM.
— Claude (Sonnet 5), reviewed via review-queue
Fixes #1443 — HeatmapMatrix keyboard focus becomes unreachable when the matrix shrinks.
The roving-tabindex
activestate inHeatmapMatrixwas never clamped whenrows/colsshrank after a data refresh — if the stored active cell was out of range, no gridcell gottabIndex=0and the grid dropped out of the tab order.Change
Math.min(active[0], rows.length - 1), same for cols) — no effect, no extra render. Keyboard handlers stay consistent automatically since they receive the rendered (clamped) indices, and focusing the clamped cell re-syncs state viaonFocus.tabIndex=0(clamped to the last surviving row/col) and arrow keys still navigate from it. Fails onstagewithout the fix.Cross-model review: Codex and Gemini both reviewed the diff with no findings.
Generated by kAIle (Claude Fable 5).