Skip to content

fix(table): keep cell content's keystrokes, and scope row scrolling to the focused grid - #20

Open
Taleef7 wants to merge 2 commits into
mieweb:mainfrom
Taleef7:fix/table-keyboard-nav-interactive-content
Open

fix(table): keep cell content's keystrokes, and scope row scrolling to the focused grid#20
Taleef7 wants to merge 2 commits into
mieweb:mainfrom
Taleef7:fix/table-keyboard-nav-interactive-content

Conversation

@Taleef7

@Taleef7 Taleef7 commented Jul 29, 2026

Copy link
Copy Markdown

Fixes #19.

Two independent fixes, one commit each.

Interactive cell content keeps its own keys

handleKeyDown returns early when the event originates inside an anchor, button, input, select, textarea, or contenteditable. Without it, the grid's bare-letter bindings (j/k) make an in-cell input impossible to type into, and Enter on an in-cell link activates the row instead of following the link. preventDefault() was being called before anything decided the key was meant for the grid.

Row scrolling is scoped to the grid that owns the event

useKeyboardNav takes an optional containerRef and queries within it, falling back to document when none is passed — so existing callers are unaffected and the signature change is not breaking. PlainTable passes the tableRef it already holds. Row numbers restart at 0 in every grid, so the previous document-wide lookup found the first match on the page rather than the grid being navigated.

Verification

npm run typecheck, npm run lint (eslint + i18n), and npm test all pass — 87 tests.

No test included, and I would rather say why than leave it unexplained. Both behaviors are DOM-level. The unit suite has no jsdom or testing-library and covers pure helpers only, and the e2e harness has no fixture that renders interactive content inside a cell — so testing this properly means adding a harness fixture, which felt like more than a two-line behavioral fix should drag in. If you tell me where you would want that fixture to live, I will add it along with an e2e case.

Context

Both of these turned up using the grid through @mieweb/ui/datavis in a compliance dashboard at MIE, where cells link through to employee and case detail and one page renders three grids. I have been running these two patches against a vendored copy for several weeks.

Taleef added 2 commits July 29, 2026 14:02
handleKeyDown ran for every keydown that reached the grid, and calls
preventDefault before deciding whether the key was meant for it. Anything
interactive inside a cell is therefore unusable from the keyboard: Enter on a
link activates the row instead of following the link, and because the nav binds
bare letters, typing "j" or "k" in an in-cell input moves the row selection
instead of typing a character. Space, Home and End are taken the same way.

Return early when the event originates inside an anchor, button, input, select,
textarea or contenteditable, so that content keeps its own keys. Mouse users
never saw this, which is what makes it specifically an accessibility bug.
scrollActiveRowIntoView looked up [data-row-num="N"] against document. Row
numbers restart at 0 in every grid, so on a page with more than one grid the
lookup finds the first match in document order rather than the grid being
navigated — arrow keys scroll a different table than the one with focus.

useKeyboardNav now takes an optional containerRef and queries within it,
falling back to document when none is supplied so existing callers are
unaffected. PlainTable passes the tableRef it already holds.
Copilot AI review requested due to automatic review settings July 29, 2026 18:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table keyboard nav consumes keys meant for cell content, and scrolls the wrong grid when a page has several

2 participants