Repository navigation
fix: focus same row when tabbing to new body cell outside viewport - #13031
Conversation
0959ef5 to
f954814
Compare
3f0bfd8 to
b91c34c
Compare
The fallback that moves focus to the first visible column looked up the cell by its position in `column._cells`. Columns do not share one row order there once a column is added, so Tab could land on a different row. Look the cell up through the row element instead. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
b91c34c to
16715df
Compare
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 1 comment.
| Finding | |
|---|---|
With lazy column rendering the lookup can return undefined, which later leads to undefined.focus() |
| const rowIndex = focusStepTarget._column._cells.indexOf(focusStepTarget); | ||
| focusStepTarget = firstVisibleColumn._cells[rowIndex]; | ||
| const row = focusStepTarget.parentElement; | ||
| focusStepTarget = [...row.children].find((cell) => cell._column === firstVisibleColumn); |
There was a problem hiding this comment.
undefined.focus()
In columnRendering="lazy" mode, body cells of out-of-viewport columns are removed from their row, and __updateColumnsBodyContentHidden() only runs 100 ms after the last scroll event. Inside that window firstVisibleColumn is computed from the fresh scrollLeft while the row still holds the cells from the previous scroll position, so the first visible column has no cell in row.children and find yields undefined.
Two results:
_onTabKeyDownreturns early, so Tab escapes the grid instead of entering the body._onFocusIncalls_predictFocusStepTarget(...).focus()without a null check, so tabbing into a grid with hidden header rows throws.
The previous column._cells[rowIndex] lookup kept working for detached cells. row.__cells, which __initRow maintains in column order including detached cells, would preserve that.
vaadin-grid-keyboard-navigation-mixin.js:680 · correctness
There was a problem hiding this comment.
Fixed by adding this._debounceColumnContentVisibility?.flush() in _predictFocusStepTarget.
Right after a horizontal scroll in lazy column rendering mode the rows keep the cells of the previous scroll position for up to 100 ms, so the first visible column can have no cell in the row and Tab left the grid. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
|
This ticket/PR has been released with Vaadin 25.4.0-alpha3. |



Description
Related to #12779
When Tab enters the body and the remembered cell is scrolled out of view horizontally, grid focuses the first visible column's cell on the same row instead. That cell was looked up by position in
column._cells, which assumes all columns store their cells in the same row order. A column added later stores them in a different order, so focus landed on another row.column._cellsType of change
How to test
dev/grid.htmland make the window narrow enough for the grid to scroll horizontally🤖 Generated with Claude Code