Skip to content

Commit 101eaba

Browse files
fix: only show tooltip if the target cell is fully visible (#7749) (#7753)
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
1 parent 5415d48 commit 101eaba

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

integration/tests/grid-tooltip.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('tooltip', () => {
3232
<vaadin-grid>
3333
<vaadin-grid-column path="firstName"></vaadin-grid-column>
3434
<vaadin-grid-column path="lastName"></vaadin-grid-column>
35+
<vaadin-grid-column path="lastName"></vaadin-grid-column>
3536
<vaadin-tooltip slot="tooltip"></vaadin-tooltip>
3637
</vaadin-grid>
3738
`);
@@ -262,6 +263,67 @@ describe('tooltip', () => {
262263
});
263264
});
264265

266+
describe('cell not fully visible', () => {
267+
['ltr', 'rtl'].forEach((direction) => {
268+
describe(`${direction}`, () => {
269+
const isRTL = direction === 'rtl';
270+
271+
before(() => {
272+
document.documentElement.setAttribute('dir', direction);
273+
});
274+
275+
after(() => {
276+
document.documentElement.removeAttribute('dir');
277+
});
278+
279+
beforeEach(async () => {
280+
tooltip.hoverDelay = 0;
281+
grid.style.width = '150px';
282+
flushGrid(grid);
283+
await nextRender();
284+
});
285+
286+
it('should not show tooltip when cell not fully visible at the start', async () => {
287+
grid.$.table.scrollLeft = isRTL ? -150 : 150;
288+
await nextRender();
289+
flushGrid(grid);
290+
291+
mouseenter(getCell(grid, 0));
292+
expect(tooltip.opened).to.be.false;
293+
});
294+
295+
it('should not show tooltip when cell not fully visible at the end', () => {
296+
mouseenter(getCell(grid, 1));
297+
expect(tooltip.opened).to.be.false;
298+
});
299+
300+
it('should not show tooltip when cell is partially covered by frozen cell', async () => {
301+
grid.querySelector('vaadin-grid-column').frozen = true;
302+
await nextRender();
303+
304+
grid.$.table.scrollLeft = isRTL ? -100 : 100;
305+
await nextRender();
306+
flushGrid(grid);
307+
308+
mouseenter(getCell(grid, 1));
309+
expect(tooltip.opened).to.be.false;
310+
});
311+
312+
it('should not show tooltip when cell is partially covered by frozen to end cell', async () => {
313+
grid.querySelectorAll('vaadin-grid-column')[2].frozenToEnd = true;
314+
await nextRender();
315+
316+
grid.$.table.scrollLeft = isRTL ? -100 : 100;
317+
await nextRender();
318+
flushGrid(grid);
319+
320+
mouseenter(getCell(grid, 1));
321+
expect(tooltip.opened).to.be.false;
322+
});
323+
});
324+
});
325+
});
326+
265327
describe('delay', () => {
266328
before(() => {
267329
Tooltip.setDefaultFocusDelay(0);

packages/grid/src/vaadin-grid-mixin.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,13 @@ export const GridMixin = (superClass) =>
10041004
// Check if there is a slotted vaadin-tooltip element.
10051005
const tooltip = this._tooltipController.node;
10061006
if (tooltip && tooltip.isConnected) {
1007-
this._tooltipController.setTarget(event.target);
1007+
const target = event.target;
1008+
1009+
if (!this.__isCellFullyVisible(target)) {
1010+
return;
1011+
}
1012+
1013+
this._tooltipController.setTarget(target);
10081014
this._tooltipController.setContext(this.getEventContext(event));
10091015

10101016
// Trigger opening using the corresponding delay.
@@ -1015,6 +1021,33 @@ export const GridMixin = (superClass) =>
10151021
}
10161022
}
10171023

1024+
/** @private */
1025+
__isCellFullyVisible(cell) {
1026+
if (cell.hasAttribute('frozen') || cell.hasAttribute('frozen-to-end')) {
1027+
// Frozen cells are always fully visible
1028+
return true;
1029+
}
1030+
1031+
let { left, right } = this.getBoundingClientRect();
1032+
1033+
const frozen = [...cell.parentNode.children].find((cell) => cell.hasAttribute('last-frozen'));
1034+
if (frozen) {
1035+
const frozenRect = frozen.getBoundingClientRect();
1036+
left = this.__isRTL ? left : frozenRect.right;
1037+
right = this.__isRTL ? frozenRect.left : right;
1038+
}
1039+
1040+
const frozenToEnd = [...cell.parentNode.children].find((cell) => cell.hasAttribute('first-frozen-to-end'));
1041+
if (frozenToEnd) {
1042+
const frozenToEndRect = frozenToEnd.getBoundingClientRect();
1043+
left = this.__isRTL ? frozenToEndRect.right : left;
1044+
right = this.__isRTL ? right : frozenToEndRect.left;
1045+
}
1046+
1047+
const cellRect = cell.getBoundingClientRect();
1048+
return cellRect.left >= left && cellRect.right <= right;
1049+
}
1050+
10181051
/** @protected */
10191052
_hideTooltip(immediate) {
10201053
const tooltip = this._tooltipController && this._tooltipController.node;

0 commit comments

Comments
 (0)