Skip to content

refactor: centralize grid cell event handlers#12138

Merged
vursen merged 1 commit into
mainfrom
refactor-grid-cell-keydown-handler
Jul 15, 2026
Merged

refactor: centralize grid cell event handlers#12138
vursen merged 1 commit into
mainfrom
refactor-grid-cell-keydown-handler

Conversation

@vursen

@vursen vursen commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

The grid attaches cell event listeners in different places and in different ways: the tooltip mouse listeners are created as new closures for every cell in _createCell, while the keydown listener is bound per column and attached in two separate places in __initRow, but only for columns that define _onCellKeyDown.

This moves all cell event handling to the grid itself:

  • The grid gets shared bound methods (__onCellMouseEnter, __onCellMouseLeave, __onCellMouseDown, __onCellKeyDown) that are attached once per cell in _createCell.
  • On keydown, the cell delegates to its column through column.__onCellKeyDown, so the per-column listener setup in __initRow is no longer needed. The selection column's _onCellKeyDown is renamed to __onCellKeyDown to match.
  • Cells without a column (the row details cell) skip the delegation, so behavior stays the same.

This also prepares for rendering header and footer rows declaratively with Lit, where the same handler references can be used directly in the template.

Extracted from #12134

Part of #10789

Replace the per-cell inline tooltip listeners and the per-column
`keydown` binding with shared bound methods on the grid. Cells now
delegate `keydown` to their column via `column.__onCellKeyDown`, so the
selection column's `_onCellKeyDown` is renamed to `__onCellKeyDown`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@vursen vursen changed the title refactor: centralize grid cell event handlers on the grid refactor: centralize grid cell event handlers Jul 15, 2026
@vursen
vursen requested a review from web-padawan July 15, 2026 07:11
@sissbruecker

Copy link
Copy Markdown
Member

/code-review

@vaadin-review-bot vaadin-review-bot 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.

Reviewed the changes — left 1 comment.

Finding
Mouse listeners are now registered on touch devices, where the base code skipped them entirely.

this._hideTooltip(true);
});
}
cell.addEventListener('mouseenter', this.__onCellMouseEnter);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚡ Mouse listeners are now registered on touch devices, where the base code skipped them entirely.

In the base code, _createCell attached mouseenter/mouseleave/mousedown listeners only inside if (!isAndroid && !isIOS), so on Android and iOS no mouse listeners were attached at all. The refactor moved that guard from registration into each handler body (__onCellMouseEnter/Leave/Down), so _createCell now unconditionally calls cell.addEventListener three times per cell on every platform.

On touch devices this adds three registered listeners per cell that immediately return without doing anything. Behavior is unchanged, but the listeners are pure overhead. Keeping the if (!isAndroid && !isIOS) check at registration time — while still using the shared bound methods — avoids attaching dead listeners and lets each handler drop its now-redundant internal platform check.

vaadin-grid-mixin.js:405 · efficiency · confirmed

@vursen vursen Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's intentional. It allows us to reuse these handlers.

@vursen
vursen requested a review from sissbruecker July 15, 2026 07:34
@vursen
vursen merged commit 157e5b8 into main Jul 15, 2026
16 checks passed
@vursen
vursen deleted the refactor-grid-cell-keydown-handler branch July 15, 2026 08:17
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.

4 participants