Skip to content

Commit daa736e

Browse files
authored
fix: add support for delay properties to grid tooltip (#4677)
1 parent d0d6c31 commit daa736e

4 files changed

Lines changed: 67 additions & 9 deletions

File tree

‎dev/grid.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<vaadin-grid-column path="name" width="200px" flex-shrink="0"></vaadin-grid-column>
4444
<vaadin-grid-column path="name" width="200px" flex-shrink="0"></vaadin-grid-column>
4545

46-
<vaadin-tooltip slot="tooltip"></vaadin-tooltip>
46+
<vaadin-tooltip slot="tooltip" hover-delay="500" hide-delay="500"></vaadin-tooltip>
4747
</vaadin-grid>
4848
</body>
4949
</html>

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

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { expect } from '@esm-bundle/chai';
22
import {
33
arrowDown,
4+
aTimeout,
45
enter,
56
escKeyDown,
67
fixtureSync,
78
focusin,
89
focusout,
910
mousedown,
1011
nextFrame,
12+
nextRender,
1113
tabKeyDown,
1214
} from '@vaadin/testing-helpers';
1315
import sinon from 'sinon';
@@ -23,7 +25,7 @@ function getHeaderCell(grid, index = 0) {
2325
describe('tooltip', () => {
2426
let grid, tooltip;
2527

26-
beforeEach(() => {
28+
beforeEach(async () => {
2729
grid = fixtureSync(`
2830
<vaadin-grid>
2931
<vaadin-grid-column path="firstName"></vaadin-grid-column>
@@ -41,6 +43,7 @@ describe('tooltip', () => {
4143
tooltip.generator = ({ column, item }) => {
4244
return column && column.path && item ? `${column.path}: ${item[column.path]}` : '';
4345
};
46+
await nextRender();
4447
});
4548

4649
it('should set manual on the tooltip to true', () => {
@@ -53,13 +56,32 @@ describe('tooltip', () => {
5356
expect(tooltip.opened).to.be.true;
5457
});
5558

59+
it('should use hover delay on cell mouseenter', async () => {
60+
tooltip.hoverDelay = 10;
61+
const cell = getCell(grid, 0);
62+
mouseenter(cell);
63+
expect(tooltip.opened).to.be.false;
64+
await aTimeout(10);
65+
expect(tooltip.opened).to.be.true;
66+
});
67+
5668
it('should hide tooltip on cell mouseleave', () => {
5769
const cell = getCell(grid, 0);
5870
mouseenter(cell);
5971
mouseleave(cell);
6072
expect(tooltip.opened).to.be.false;
6173
});
6274

75+
it('should use hide delay on cell mouseleave', async () => {
76+
tooltip.hideDelay = 10;
77+
const cell = getCell(grid, 0);
78+
mouseenter(cell);
79+
mouseleave(cell);
80+
expect(tooltip.opened).to.be.true;
81+
await aTimeout(10);
82+
expect(tooltip.opened).to.be.false;
83+
});
84+
6385
it('should set tooltip target on cell mouseenter', () => {
6486
const cell = getCell(grid, 0);
6587
mouseenter(cell);
@@ -91,13 +113,31 @@ describe('tooltip', () => {
91113
expect(tooltip.opened).to.be.false;
92114
});
93115

116+
it('should not use hide delay on cell mousedown', () => {
117+
tooltip.hideDelay = 10;
118+
const cell = getCell(grid, 0);
119+
mouseenter(cell);
120+
mousedown(cell);
121+
expect(tooltip.opened).to.be.false;
122+
});
123+
94124
it('should show tooltip on cell keyboard focus', () => {
95125
const cell = getCell(grid, 0);
96126
tabKeyDown(document.body);
97127
focusin(cell);
98128
expect(tooltip.opened).to.be.true;
99129
});
100130

131+
it('should use focus delay on cell keyboard focus', async () => {
132+
tooltip.focusDelay = 10;
133+
const cell = getCell(grid, 0);
134+
tabKeyDown(document.body);
135+
focusin(cell);
136+
expect(tooltip.opened).to.be.false;
137+
await aTimeout(10);
138+
expect(tooltip.opened).to.be.true;
139+
});
140+
101141
it('should set tooltip target on cell keyboard focus', () => {
102142
const cell = getCell(grid, 0);
103143
tabKeyDown(document.body);
@@ -151,6 +191,15 @@ describe('tooltip', () => {
151191
expect(tooltip.opened).to.be.false;
152192
});
153193

194+
it('should not use hide delay on grid cell content Esc', () => {
195+
tooltip.hideDelay = 10;
196+
const cell = getCell(grid, 0);
197+
tabKeyDown(document.body);
198+
focusin(cell._content);
199+
escKeyDown(cell._content);
200+
expect(tooltip.opened).to.be.false;
201+
});
202+
154203
it('should set tooltip opened to false when the grid is removed', () => {
155204
const cell = getCell(grid, 0);
156205
mouseenter(cell);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ export const KeyboardNavigationMixin = (superClass) =>
587587
}
588588

589589
if (key === 'Escape') {
590-
this._hideTooltip();
590+
this._hideTooltip(true);
591591
}
592592
}
593593

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class Grid extends ElementMixin(
400400
disconnectedCallback() {
401401
super.disconnectedCallback();
402402
this.isAttached = false;
403-
this._hideTooltip();
403+
this._hideTooltip(true);
404404
}
405405

406406
/** @private */
@@ -683,7 +683,7 @@ class Grid extends ElementMixin(
683683
});
684684

685685
cell.addEventListener('mousedown', () => {
686-
this._hideTooltip();
686+
this._hideTooltip(true);
687687
});
688688
}
689689

@@ -1016,16 +1016,25 @@ class Grid extends ElementMixin(
10161016
*/
10171017
_showTooltip(event) {
10181018
// Check if there is a slotted vaadin-tooltip element.
1019-
if (this._tooltipController.node && this._tooltipController.node.isConnected) {
1019+
const tooltip = this._tooltipController.node;
1020+
if (tooltip && tooltip.isConnected) {
10201021
this._tooltipController.setTarget(event.target);
10211022
this._tooltipController.setContext(this.getEventContext(event));
1022-
this._tooltipController.setOpened(true);
1023+
1024+
// Trigger opening using the corresponding delay.
1025+
tooltip._stateController.open({
1026+
focus: event.type === 'focusin',
1027+
hover: event.type === 'mouseenter',
1028+
});
10231029
}
10241030
}
10251031

10261032
/** @protected */
1027-
_hideTooltip() {
1028-
this._tooltipController.setOpened(false);
1033+
_hideTooltip(immediate) {
1034+
const tooltip = this._tooltipController.node;
1035+
if (tooltip) {
1036+
tooltip._stateController.close(immediate);
1037+
}
10291038
}
10301039

10311040
/**

0 commit comments

Comments
 (0)