Skip to content

Commit

Permalink
fix: tooltip.hide should pass the clientX and clientY
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Dec 11, 2023
1 parent fbd1a25 commit ec656fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion __tests__/integration/components/tooltip/tooltip-10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const Tooltip10 = () => {
tooltip.show(e.offsetX, e.offsetY);
});
group.addEventListener('mouseleave', (e: any) => {
tooltip.hide(e.offsetX, e.offsetY);
tooltip.hide(e.clientX, e.clientY);
});

return group;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/components/tooltip/tooltip-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const Tooltip2 = () => {
tooltip.show();
});
group.addEventListener('mouseleave', (e: any) => {
tooltip.hide(e.offsetX, e.offsetY);
tooltip.hide(e.clientX, e.clientY);
});
return group;
};
Expand Down
10 changes: 6 additions & 4 deletions src/ui/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,16 @@ export class Tooltip extends Component<TooltipStyleProps> {
return this.getRelativeOffsetFromCursor(correctedPositionString as TooltipPosition);
}

private isCursorEntered(cursorX: number, cursorY: number) {
private isCursorEntered(clientX: number, clientY: number) {
// 是可捕获的,并且点在 tooltip dom 上
if (this.element) {
const { x, y, width, height } = this.element.getBoundingClientRect();
const { container } = this.attributes;
const { x: cx, y: cy } = container;
// const { container } = this.attributes;
// const { x: cx, y: cy } = container;

return new BBox(x - cx, y - cy, width, height).isPointIn(cursorX, cursorY);
// console.log(1113, [clientX, clientY], [x, y, width, height], [cx, cy], new BBox(x - cx, y - cy, width, height).isPointIn(cursorX, cursorY));

return new BBox(x, y, width, height).isPointIn(clientX, clientY);
}
return false;
}
Expand Down

0 comments on commit ec656fc

Please sign in to comment.