Skip to content

Commit 8bb8687

Browse files
authored
fix: improve target visibility observer logic and tests (#4569)
1 parent ec63c04 commit 8bb8687

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,11 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
446446

447447
/** @private */
448448
__onTargetVisibilityChange(isVisible) {
449+
const oldHidden = this.__isTargetHidden;
449450
this.__isTargetHidden = !isVisible;
450451

451-
// Open the overlay when the target is visible and has focus or hover.
452-
if (isVisible && (this.__focusInside || this.__hoverInside)) {
452+
// Open the overlay when the target becomes visible and has focus or hover.
453+
if (oldHidden && isVisible && (this.__focusInside || this.__hoverInside)) {
453454
this._open(true);
454455
return;
455456
}

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { aTimeout, escKeyDown, fixtureSync, focusout, mousedown, tabKeyDown } from '@vaadin/testing-helpers';
2+
import {
3+
aTimeout,
4+
escKeyDown,
5+
fixtureSync,
6+
focusout,
7+
mousedown,
8+
nextRender,
9+
tabKeyDown,
10+
} from '@vaadin/testing-helpers';
311
import './not-animated-styles.js';
412
import { Tooltip } from '../vaadin-tooltip.js';
513
import { mouseenter, mouseleave } from './helpers.js';
@@ -8,14 +16,16 @@ describe('timers', () => {
816
describe('delay', () => {
917
let tooltip, target, overlay;
1018

11-
beforeEach(() => {
19+
beforeEach(async () => {
1220
tooltip = fixtureSync('<vaadin-tooltip text="tooltip" delay="1"></vaadin-tooltip>');
1321
target = fixtureSync('<input>');
1422
tooltip.target = target;
1523
overlay = tooltip.shadowRoot.querySelector('vaadin-tooltip-overlay');
24+
await nextRender();
1625
});
1726

1827
afterEach(async () => {
28+
// Wait for cooldown timeout.
1929
await aTimeout(0);
2030
});
2131

@@ -37,14 +47,16 @@ describe('timers', () => {
3747
describe('hideDelay', () => {
3848
let tooltip, target, overlay;
3949

40-
beforeEach(() => {
50+
beforeEach(async () => {
4151
tooltip = fixtureSync('<vaadin-tooltip text="tooltip" hide-delay="1"></vaadin-tooltip>');
4252
target = fixtureSync('<input>');
4353
tooltip.target = target;
4454
overlay = tooltip.shadowRoot.querySelector('vaadin-tooltip-overlay');
55+
await nextRender();
4556
});
4657

4758
afterEach(async () => {
59+
// Wait for cooldown timeout.
4860
await aTimeout(1);
4961
});
5062

@@ -246,7 +258,7 @@ describe('timers', () => {
246258
describe('warmup and cooldown', () => {
247259
let wrapper, targets, tooltips, overlays;
248260

249-
beforeEach(() => {
261+
beforeEach(async () => {
250262
wrapper = fixtureSync(`
251263
<div>
252264
<vaadin-tooltip text="tooltip 1" delay="2" hide-delay="2" for="input-1"></vaadin-tooltip>
@@ -258,9 +270,11 @@ describe('timers', () => {
258270
tooltips = Array.from(wrapper.querySelectorAll('vaadin-tooltip'));
259271
targets = wrapper.querySelectorAll('input');
260272
overlays = tooltips.map((el) => el.shadowRoot.querySelector('vaadin-tooltip-overlay'));
273+
await nextRender();
261274
});
262275

263276
afterEach(async () => {
277+
// Wait for cooldown timeout.
264278
await aTimeout(2);
265279
});
266280

@@ -310,7 +324,7 @@ describe('timers', () => {
310324
mouseleave(targets[0]);
311325
await aTimeout(1);
312326

313-
expect(overlays[0].opened).to.be.false;
327+
expect(overlays[0].opened).to.be.not.ok;
314328
});
315329

316330
it('should stop closing on subsequent mouseenter during the hide delay', async () => {

0 commit comments

Comments
 (0)