Skip to content

Commit 1cab944

Browse files
authored
fix: do not reset timers when using manual mode (#4586)
1 parent 19aca5e commit 1cab944

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
389389

390390
/** @private */
391391
__onFocusin(event) {
392+
if (this.manual) {
393+
return;
394+
}
395+
392396
// Only open on keyboard focus.
393397
if (!isKeyboardActive()) {
394398
return;
@@ -412,6 +416,10 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
412416

413417
/** @private */
414418
__onFocusout(event) {
419+
if (this.manual) {
420+
return;
421+
}
422+
415423
// Do not close when moving focus within a component.
416424
if (this.target.contains(event.relatedTarget)) {
417425
return;
@@ -439,6 +447,10 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
439447

440448
/** @private */
441449
__onMouseEnter() {
450+
if (this.manual) {
451+
return;
452+
}
453+
442454
if (typeof this.shouldShow === 'function' && this.shouldShow(this.target) !== true) {
443455
return;
444456
}
@@ -457,6 +469,10 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
457469

458470
/** @private */
459471
__onMouseLeave() {
472+
if (this.manual) {
473+
return;
474+
}
475+
460476
this.__hoverInside = false;
461477

462478
if (!this.__focusInside) {

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,5 +541,82 @@ describe('timers', () => {
541541

542542
expect(overlays[0].opened).to.be.false;
543543
});
544+
545+
it('should not keep warmed up state on mouseenter to the manual tooltip target', async () => {
546+
tooltips[1].manual = true;
547+
548+
mouseenter(targets[0]);
549+
await aTimeout(2);
550+
551+
mouseleave(targets[0]);
552+
mouseenter(targets[1]);
553+
await aTimeout(2);
554+
555+
expect(overlays[0].opened).to.be.false;
556+
557+
mouseleave(targets[1]);
558+
mouseenter(targets[0]);
559+
expect(overlays[0].opened).to.be.false;
560+
561+
await aTimeout(2);
562+
expect(overlays[0].opened).to.be.true;
563+
});
564+
565+
it('should not keep warmed up state on focusout to the manual tooltip target', async () => {
566+
tooltips[1].manual = true;
567+
568+
tabKeyDown(document.body);
569+
focusin(targets[0]);
570+
await aTimeout(2);
571+
572+
focusout(targets[0], targets[1]);
573+
focusin(targets[1], targets[0]);
574+
await aTimeout(2);
575+
576+
expect(overlays[0].opened).to.be.false;
577+
578+
focusout(targets[1], targets[0]);
579+
focusin(targets[0], targets[1]);
580+
581+
expect(overlays[0].opened).to.be.false;
582+
583+
await aTimeout(2);
584+
expect(overlays[0].opened).to.be.true;
585+
});
586+
587+
it('should not restart cooldown on mouseleave from the manual tooltip target', async () => {
588+
tooltips[1].manual = true;
589+
590+
mouseenter(targets[0]);
591+
await aTimeout(2);
592+
593+
mouseleave(targets[0]);
594+
mouseenter(targets[1]);
595+
await aTimeout(1);
596+
597+
mouseleave(targets[1]);
598+
await aTimeout(1);
599+
600+
mouseenter(targets[0]);
601+
expect(overlays[0].opened).to.be.false;
602+
});
603+
604+
it('should not restart cooldown on focusout from the manual tooltip target', async () => {
605+
tooltips[1].manual = true;
606+
607+
tabKeyDown(document.body);
608+
focusin(targets[0]);
609+
await aTimeout(2);
610+
611+
focusout(targets[0], targets[1]);
612+
focusin(targets[1], targets[0]);
613+
await aTimeout(1);
614+
615+
focusout(targets[1]);
616+
await aTimeout(1);
617+
618+
focusin(targets[0]);
619+
expect(overlays[0].opened).to.be.false;
620+
});
544621
});
545622
});

0 commit comments

Comments
 (0)