Skip to content

Commit 33cadc8

Browse files
driskullbenelan
authored andcommitted
fix(tooltip): do not open after the pointer has moved off of the reference element (#11599)
**Related Issue:** #11091 ## Summary - No longer opens the tooltip after the pointer has moved off of the reference element - Clears open timeout when pointer moved and the same tooltip's reference element is no longer hovered - If opening and the hover tooltip doesn't match the tooltip being opened, nothing happens. - Modify delay opening tooltips when a tooltip is already open from `0ms` to `100ms` which is a third the usual time. - Modify delay closing tooltips from `500ms` to `450ms` which is a factor of `1.5` times the opening delay.
1 parent 7b99bd8 commit 33cadc8

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/calcite-components/src/components/tooltip/TooltipManager.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-strict-ignore
22
import { getShadowRootNode } from "../../utils/dom";
33
import { ReferenceElement } from "../../utils/floating-ui";
4-
import { TOOLTIP_OPEN_DELAY_MS, TOOLTIP_CLOSE_DELAY_MS } from "./resources";
4+
import { TOOLTIP_OPEN_DELAY_MS, TOOLTIP_QUICK_OPEN_DELAY_MS, TOOLTIP_CLOSE_DELAY_MS } from "./resources";
55
import { getEffectiveReferenceElement } from "./utils";
66
import type { Tooltip } from "./tooltip";
77

@@ -26,6 +26,8 @@ export default class TooltipManager {
2626

2727
private clickedTooltip: Tooltip["el"] = null;
2828

29+
private hoveredTooltip: Tooltip["el"] = null;
30+
2931
// --------------------------------------------------------------------------
3032
//
3133
// Public Methods
@@ -116,6 +118,12 @@ export default class TooltipManager {
116118
return;
117119
}
118120

121+
if (tooltip !== this.hoveredTooltip) {
122+
this.clearHoverOpenTimeout();
123+
}
124+
125+
this.hoveredTooltip = tooltip;
126+
119127
if (tooltip) {
120128
this.openHoveredTooltip(tooltip);
121129
} else if (activeTooltip?.open) {
@@ -266,15 +274,15 @@ export default class TooltipManager {
266274
private openHoveredTooltip = (tooltip: Tooltip["el"]): void => {
267275
this.hoverOpenTimeout = window.setTimeout(
268276
() => {
269-
if (this.hoverOpenTimeout === null) {
277+
if (this.hoverOpenTimeout === null || tooltip !== this.hoveredTooltip) {
270278
return;
271279
}
272280

273281
this.clearHoverCloseTimeout();
274282
this.closeTooltipIfNotActive(tooltip);
275283
this.toggleTooltip(tooltip, true);
276284
},
277-
this.activeTooltip?.open ? 0 : TOOLTIP_OPEN_DELAY_MS,
285+
this.activeTooltip?.open ? TOOLTIP_QUICK_OPEN_DELAY_MS : TOOLTIP_OPEN_DELAY_MS,
278286
);
279287
};
280288

packages/calcite-components/src/components/tooltip/resources.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const CSS = {
44
};
55

66
export const TOOLTIP_OPEN_DELAY_MS = 300;
7-
export const TOOLTIP_CLOSE_DELAY_MS = 500;
7+
export const TOOLTIP_QUICK_OPEN_DELAY_MS = TOOLTIP_OPEN_DELAY_MS / 3;
8+
export const TOOLTIP_CLOSE_DELAY_MS = TOOLTIP_OPEN_DELAY_MS * 1.5;
89

910
export const ARIA_DESCRIBED_BY = "aria-describedby";

packages/calcite-components/src/components/tooltip/tooltip.e2e.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { accessible, defaults, floatingUIOwner, hidden, openClose, renders, them
55
import { html } from "../../../support/formatting";
66
import { getElementXY, GlobalTestProps, skipAnimations } from "../../tests/utils";
77
import { FloatingCSS } from "../../utils/floating-ui";
8-
import { TOOLTIP_OPEN_DELAY_MS, TOOLTIP_CLOSE_DELAY_MS, CSS } from "./resources";
8+
import { TOOLTIP_OPEN_DELAY_MS, TOOLTIP_CLOSE_DELAY_MS, CSS, TOOLTIP_QUICK_OPEN_DELAY_MS } from "./resources";
99
import type { Tooltip } from "./tooltip";
1010

1111
interface PointerMoveOptions {
@@ -1236,7 +1236,7 @@ describe("calcite-tooltip", () => {
12361236
});
12371237
});
12381238

1239-
it("should open tooltip instantly if another tooltip is already visible", async () => {
1239+
it("should open tooltip faster if another tooltip is already visible", async () => {
12401240
const page = await newE2EPage();
12411241

12421242
await page.setContent(
@@ -1260,7 +1260,7 @@ describe("calcite-tooltip", () => {
12601260
expect(await tooltip2.getProperty("open")).toBe(false);
12611261

12621262
await dispatchPointerEvent(page, "#ref2");
1263-
await page.waitForTimeout(0);
1263+
await page.waitForTimeout(TOOLTIP_QUICK_OPEN_DELAY_MS);
12641264
expect(await tooltip1.getProperty("open")).toBe(false);
12651265
expect(await tooltip2.getProperty("open")).toBe(true);
12661266
});

0 commit comments

Comments
 (0)