Skip to content

Commit

Permalink
fix(tooltip): close tooltips on prevented pointer move events (#11557)
Browse files Browse the repository at this point in the history
**Related Issue:** #11541

## Summary

- Close tooltip even when `pointer-move` event is cancelled
- Add test
  • Loading branch information
driskull authored and benelan committed Feb 19, 2025
1 parent 78f3543 commit 470df20
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default class TooltipManager {

private pointerMoveHandler = (event: PointerEvent): void => {
if (event.defaultPrevented) {
this.closeHoveredTooltip();
return;
}

Expand Down
29 changes: 29 additions & 0 deletions packages/calcite-components/src/components/tooltip/tooltip.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,35 @@ describe("calcite-tooltip", () => {
expect(await positionContainer.isVisible()).toBe(false);
});

it("should close when hover event is prevented", async () => {
const page = await newE2EPage();
await page.setContent(html`
<calcite-tooltip reference-element="ref">content</calcite-tooltip>
<div id="button-container">
<div id="ref">referenceElement</div>
</div>
`);
await skipAnimations(page);
await page.waitForChanges();

const positionContainer = await page.find(`calcite-tooltip >>> .${CSS.positionContainer}`);

const ref = await page.find("#ref");
await ref.hover();
await page.waitForTimeout(TOOLTIP_OPEN_DELAY_MS);
expect(await positionContainer.isVisible()).toBe(true);

await page.$eval("#button-container", (buttonContainer) => {
buttonContainer.addEventListener("pointermove", (event) => {
event.preventDefault();
});
});

await ref.hover();
await page.waitForTimeout(TOOLTIP_CLOSE_DELAY_MS);
expect(await positionContainer.isVisible()).toBe(false);
});

it("should honor hover interaction with span inside", async () => {
const page = await newE2EPage();

Expand Down

0 comments on commit 470df20

Please sign in to comment.