Fix workspace hover card safe zone

This commit is contained in:
Mohamed Boudra
2026-04-22 18:22:20 +07:00
parent 3a0161d051
commit 637109eab0
2 changed files with 26 additions and 3 deletions
@@ -111,13 +111,29 @@ describe("useHoverSafeZone", () => {
});
act(() => pointerMove(110, 40));
expect(onEnterSafeZone).toHaveBeenCalledTimes(1);
expect(onLeaveSafeZone).not.toHaveBeenCalled();
act(() => pointerMove(300, 40));
expect(onLeaveSafeZone).toHaveBeenCalledTimes(1);
act(() => pointerMove(130, 40));
expect(onEnterSafeZone).toHaveBeenCalledTimes(1);
expect(onEnterSafeZone).toHaveBeenCalledTimes(2);
});
it("refreshes the safe-zone enter callback while moving inside", () => {
const onEnterSafeZone = vi.fn();
const onLeaveSafeZone = vi.fn();
act(() => {
root?.render(<Harness onEnterSafeZone={onEnterSafeZone} onLeaveSafeZone={onLeaveSafeZone} />);
});
act(() => pointerMove(110, 40));
act(() => pointerMove(130, 40));
expect(onEnterSafeZone).toHaveBeenCalledTimes(2);
expect(onLeaveSafeZone).not.toHaveBeenCalled();
});
it("treats leaving the browser window as leaving the safe zone", () => {
@@ -54,8 +54,15 @@ export function useHoverSafeZone({
const contentRect = contentNode ? contentNode.getBoundingClientRect() : null;
const inside = isInsideSafeZone(triggerRect, contentRect, event.clientX, event.clientY);
if (inside) enterSafeZone();
else leaveSafeZone();
if (inside) {
if (wasInside) {
onEnterSafeZone();
return;
}
enterSafeZone();
return;
}
leaveSafeZone();
}
function handlePointerOut(event: PointerEvent) {