Skip to content

Commit 62999e5

Browse files
authored
fix: allow setting individual tooltip delays to 0 (#7707)
1 parent e35ae49 commit 62999e5

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ class TooltipStateController {
5151
/** @private */
5252
get focusDelay() {
5353
const tooltip = this.host;
54-
return tooltip.focusDelay != null && tooltip.focusDelay > 0 ? tooltip.focusDelay : defaultFocusDelay;
54+
return tooltip.focusDelay != null && tooltip.focusDelay >= 0 ? tooltip.focusDelay : defaultFocusDelay;
5555
}
5656

5757
/** @private */
5858
get hoverDelay() {
5959
const tooltip = this.host;
60-
return tooltip.hoverDelay != null && tooltip.hoverDelay > 0 ? tooltip.hoverDelay : defaultHoverDelay;
60+
return tooltip.hoverDelay != null && tooltip.hoverDelay >= 0 ? tooltip.hoverDelay : defaultHoverDelay;
6161
}
6262

6363
/** @private */
6464
get hideDelay() {
6565
const tooltip = this.host;
66-
return tooltip.hideDelay != null && tooltip.hideDelay > 0 ? tooltip.hideDelay : defaultHideDelay;
66+
return tooltip.hideDelay != null && tooltip.hideDelay >= 0 ? tooltip.hideDelay : defaultHideDelay;
6767
}
6868

6969
/**

packages/tooltip/test/tooltip-timers.common.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('timers', () => {
5656

5757
afterEach(() => {
5858
resetGlobalTooltipState();
59+
Tooltip.setDefaultHoverDelay(0);
5960
});
6061

6162
it('should open the overlay after a delay on mouseenter', async () => {
@@ -71,6 +72,14 @@ describe('timers', () => {
7172
target.focus();
7273
expect(overlay.opened).to.be.true;
7374
});
75+
76+
it('should use the hover delay set to 0 and not the global delay', () => {
77+
Tooltip.setDefaultHoverDelay(50);
78+
tooltip.hoverDelay = 0;
79+
80+
mouseenter(target);
81+
expect(overlay.opened).to.be.true;
82+
});
7483
});
7584

7685
describe('focusDelay', () => {
@@ -86,6 +95,7 @@ describe('timers', () => {
8695

8796
afterEach(() => {
8897
resetGlobalTooltipState();
98+
Tooltip.setDefaultFocusDelay(0);
8999
});
90100

91101
it('should open the overlay after a delay on keyboard focus', async () => {
@@ -101,6 +111,15 @@ describe('timers', () => {
101111
mouseenter(target);
102112
expect(overlay.opened).to.be.true;
103113
});
114+
115+
it('should use the focus delay set to 0 and not the global delay', () => {
116+
Tooltip.setDefaultFocusDelay(50);
117+
tooltip.focusDelay = 0;
118+
119+
tabKeyDown(document.body);
120+
target.focus();
121+
expect(overlay.opened).to.be.true;
122+
});
104123
});
105124

106125
describe('hideDelay', () => {
@@ -116,6 +135,7 @@ describe('timers', () => {
116135

117136
afterEach(() => {
118137
resetGlobalTooltipState();
138+
Tooltip.setDefaultHideDelay(0);
119139
});
120140

121141
it('should close the overlay after a hide delay on mouseleave', async () => {
@@ -135,6 +155,15 @@ describe('timers', () => {
135155
expect(overlay.opened).to.be.false;
136156
});
137157

158+
it('should use the hide delay set to 0 and not the global delay', () => {
159+
Tooltip.setDefaultHideDelay(50);
160+
tooltip.hideDelay = 0;
161+
162+
mouseenter(target);
163+
mouseleave(target);
164+
expect(overlay.opened).to.be.false;
165+
});
166+
138167
it('should close the overlay immediately on mousedown', () => {
139168
tabKeyDown(document.body);
140169
target.focus();

0 commit comments

Comments
 (0)