Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 43 additions & 22 deletions packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export const GridMixin = (superClass) =>
return lastVisibleItem ? lastVisibleItem.index : undefined;
}

constructor() {
super();

this.__onCellMouseEnter = this.__onCellMouseEnter.bind(this);
this.__onCellMouseLeave = this.__onCellMouseLeave.bind(this);
this.__onCellMouseDown = this.__onCellMouseDown.bind(this);
this.__onCellKeyDown = this.__onCellKeyDown.bind(this);
}

/** @protected */
connectedCallback() {
super.connectedCallback();
Expand Down Expand Up @@ -351,6 +360,36 @@ export const GridMixin = (superClass) =>
return rows;
}

/** @private */
__onCellKeyDown(event) {
const cell = event.currentTarget;
cell._column?.__onCellKeyDown?.(event);
}

/** @private */
__onCellMouseEnter(event) {
// For now we only support tooltip on desktop
if (!isAndroid && !isIOS && !this.$.scroller.hasAttribute('scrolling')) {
this._showTooltip(event);
}
}

/** @private */
__onCellMouseLeave() {
// For now we only support tooltip on desktop
if (!isAndroid && !isIOS) {
this._hideTooltip();
}
}

/** @private */
__onCellMouseDown() {
// For now we only support tooltip on desktop
if (!isAndroid && !isIOS) {
this._hideTooltip(true);
}
}

/** @private */
_createCell(tagName, column) {
const contentId = (this._contentIndex = this._contentIndex + 1 || 0);
Expand All @@ -363,22 +402,10 @@ export const GridMixin = (superClass) =>
cell.id = slotName.replace('-content-', '-');
cell.setAttribute('role', tagName === 'td' ? 'gridcell' : 'columnheader');

// For now we only support tooltip on desktop
if (!isAndroid && !isIOS) {
cell.addEventListener('mouseenter', (event) => {
if (!this.$.scroller.hasAttribute('scrolling')) {
this._showTooltip(event);
}
});

cell.addEventListener('mouseleave', () => {
this._hideTooltip();
});

cell.addEventListener('mousedown', () => {
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.

cell.addEventListener('mouseleave', this.__onCellMouseLeave);
cell.addEventListener('mousedown', this.__onCellMouseDown);
cell.addEventListener('keydown', this.__onCellKeyDown);

const slot = document.createElement('slot');
slot.setAttribute('name', slotName);
Expand Down Expand Up @@ -441,9 +468,6 @@ export const GridMixin = (superClass) =>
cell = column._cells.find((cell) => cell._vacant);
if (!cell) {
cell = this._createCell('td', column);
if (column._onCellKeyDown) {
cell.addEventListener('keydown', column._onCellKeyDown.bind(column));
}
column._cells.push(cell);
}
updatePart(cell, 'cell', true);
Expand Down Expand Up @@ -492,9 +516,6 @@ export const GridMixin = (superClass) =>
cell = column[`_${section}Cell`];
if (!cell) {
cell = this._createCell(tagName);
if (column._onCellKeyDown) {
cell.addEventListener('keydown', column._onCellKeyDown.bind(column));
}
}
cell._column = column;
row.appendChild(cell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
}

/** @private */
_onCellKeyDown(e) {
__onCellKeyDown(e) {
const target = e.composedPath()[0];
// Toggle on Space without having to enter interaction mode first
if (e.keyCode !== 32) {
Expand Down
Loading