Fix workspace hover card safe zone
This commit is contained in:
@@ -111,13 +111,29 @@ describe("useHoverSafeZone", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
act(() => pointerMove(110, 40));
|
act(() => pointerMove(110, 40));
|
||||||
|
expect(onEnterSafeZone).toHaveBeenCalledTimes(1);
|
||||||
expect(onLeaveSafeZone).not.toHaveBeenCalled();
|
expect(onLeaveSafeZone).not.toHaveBeenCalled();
|
||||||
|
|
||||||
act(() => pointerMove(300, 40));
|
act(() => pointerMove(300, 40));
|
||||||
expect(onLeaveSafeZone).toHaveBeenCalledTimes(1);
|
expect(onLeaveSafeZone).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
act(() => pointerMove(130, 40));
|
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", () => {
|
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 contentRect = contentNode ? contentNode.getBoundingClientRect() : null;
|
||||||
|
|
||||||
const inside = isInsideSafeZone(triggerRect, contentRect, event.clientX, event.clientY);
|
const inside = isInsideSafeZone(triggerRect, contentRect, event.clientX, event.clientY);
|
||||||
if (inside) enterSafeZone();
|
if (inside) {
|
||||||
else leaveSafeZone();
|
if (wasInside) {
|
||||||
|
onEnterSafeZone();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
enterSafeZone();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
leaveSafeZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePointerOut(event: PointerEvent) {
|
function handlePointerOut(event: PointerEvent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user