Skip to content

Commit 39e4d72

Browse files
DiegoCardosoclaude
andauthored
fix: show grid tooltip on partially visible cells (#12996)
## Description Fixes vaadin/flow-components#10350 Related to #7749, #10728 #7749 added a check that showed the cell tooltip only when the whole cell was visible, because the tooltip could go outside the viewport (#7744). Since #10728 (25.1), the tooltip itself stays inside the viewport, so the check is no longer needed. The check also had a side effect: a cell wider than the area next to frozen columns could never be fully visible, so its tooltip never showed. - Removed the full visibility check from the grid, so the cell tooltip shows on hover and keyboard focus whenever part of the cell is visible - Changed the `cell not fully visible` integration tests to expect the tooltip for cells cut at the grid edges and cells partially covered by frozen and frozen-to-end cells, in LTR and RTL - Added integration tests for keyboard focus on a partially visible cell and for a cell wider than the area next to a frozen column As a test, I checked the provided example in the linked issue in a narrow viewport, and confirmed that the tooltip stays inside the viewport and that the text wraps: <img width="214" height="234" alt="image" src="https://github.com/user-attachments/assets/e9f4a383-9be3-4dc5-b52b-edc06a2c3b9e" /> ## Type of change - Bugfix ## How to test 1. Run `yarn start` and open `dev/grid.html` 2. Make the browser window about 400px wide, so the first non-frozen column is wider than the space next to the frozen columns 3. Hover a cell in the first non-frozen column and wait for the tooltip 4. The tooltip shows and stays inside the viewport 5. Scroll the grid so that a column is cut at the right edge, then hover one of its cells 6. The tooltip shows and stays inside the viewport > [!NOTE] > This change depends on the viewport constraint from #10728, so it should only be backported to 25.1 and later. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 27ca393 commit 39e4d72

2 files changed

Lines changed: 26 additions & 39 deletions

File tree

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,6 @@ export const GridMixin = (superClass) =>
678678
if (tooltip?.isConnected) {
679679
const target = event.target;
680680

681-
if (!this.__isCellFullyVisible(target)) {
682-
return;
683-
}
684-
685681
this._tooltipController.setTarget(target);
686682
this._tooltipController.setContext(this.getEventContext(event));
687683

@@ -693,33 +689,6 @@ export const GridMixin = (superClass) =>
693689
}
694690
}
695691

696-
/** @private */
697-
__isCellFullyVisible(cell) {
698-
if (cell.hasAttribute('frozen') || cell.hasAttribute('frozen-to-end')) {
699-
// Frozen cells are always fully visible
700-
return true;
701-
}
702-
703-
let { left, right } = this.getBoundingClientRect();
704-
705-
const frozen = [...cell.parentNode.children].find((cell) => cell.hasAttribute('last-frozen'));
706-
if (frozen) {
707-
const frozenRect = frozen.getBoundingClientRect();
708-
left = this.__isRTL ? left : frozenRect.right;
709-
right = this.__isRTL ? frozenRect.left : right;
710-
}
711-
712-
const frozenToEnd = [...cell.parentNode.children].find((cell) => cell.hasAttribute('first-frozen-to-end'));
713-
if (frozenToEnd) {
714-
const frozenToEndRect = frozenToEnd.getBoundingClientRect();
715-
left = this.__isRTL ? frozenToEndRect.right : left;
716-
right = this.__isRTL ? right : frozenToEndRect.left;
717-
}
718-
719-
const cellRect = cell.getBoundingClientRect();
720-
return cellRect.left >= left && cellRect.right <= right;
721-
}
722-
723692
/** @protected */
724693
_hideTooltip(immediate) {
725694
this._tooltipController.close(immediate);

‎test/integration/grid-tooltip.test.js‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,25 @@ describe('tooltip', () => {
277277
resetGlobalTooltipState();
278278
});
279279

280-
it('should not show tooltip when cell not fully visible at the start', async () => {
280+
it('should show tooltip when cell not fully visible at the start', async () => {
281281
grid.$.table.scrollLeft = isRTL ? -150 : 150;
282282
await nextRender();
283283
flushGrid(grid);
284284

285285
mouseenter(getCell(grid, 0));
286-
expect(tooltip.opened).to.be.false;
286+
expect(tooltip.opened).to.be.true;
287287
});
288288

289-
it('should not show tooltip when cell not fully visible at the end', () => {
289+
it('should show tooltip when cell not fully visible at the end', () => {
290290
mouseenter(getCell(grid, 1));
291-
expect(tooltip.opened).to.be.false;
291+
expect(tooltip.opened).to.be.true;
292+
});
293+
294+
it('should show tooltip on cell keyboard focus when cell not fully visible', () => {
295+
tooltip.focusDelay = 0;
296+
tabKeyDown(document.body);
297+
focusin(getCell(grid, 1));
298+
expect(tooltip.opened).to.be.true;
292299
});
293300

294301
it('should show tooltip on a frozen cell', async () => {
@@ -303,7 +310,7 @@ describe('tooltip', () => {
303310
expect(tooltip.opened).to.be.true;
304311
});
305312

306-
it('should not show tooltip when cell is partially covered by frozen cell', async () => {
313+
it('should show tooltip when cell is partially covered by frozen cell', async () => {
307314
grid.querySelector('vaadin-grid-column').frozen = true;
308315
await nextRender();
309316

@@ -312,10 +319,10 @@ describe('tooltip', () => {
312319
flushGrid(grid);
313320

314321
mouseenter(getCell(grid, 1));
315-
expect(tooltip.opened).to.be.false;
322+
expect(tooltip.opened).to.be.true;
316323
});
317324

318-
it('should not show tooltip when cell is partially covered by frozen to end cell', async () => {
325+
it('should show tooltip when cell is partially covered by frozen to end cell', async () => {
319326
grid.querySelectorAll('vaadin-grid-column')[2].frozenToEnd = true;
320327
await nextRender();
321328

@@ -324,7 +331,18 @@ describe('tooltip', () => {
324331
flushGrid(grid);
325332

326333
mouseenter(getCell(grid, 1));
327-
expect(tooltip.opened).to.be.false;
334+
expect(tooltip.opened).to.be.true;
335+
});
336+
337+
it('should show tooltip when cell is wider than the area next to frozen cell', async () => {
338+
const [frozenColumn, column] = grid.querySelectorAll('vaadin-grid-column');
339+
frozenColumn.frozen = true;
340+
column.width = '200px';
341+
await nextRender();
342+
flushGrid(grid);
343+
344+
mouseenter(getCell(grid, 1));
345+
expect(tooltip.opened).to.be.true;
328346
});
329347
});
330348
});

0 commit comments

Comments
 (0)