mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 16:27:18 +02:00
fix(org): cover touch pan click suppression
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
d8c5f5afb7
commit
90d9161065
2 files changed
+41
-1
No files matched your search
@@ -219,6 +219,33 @@ describe("OrgChart mobile gestures", () => {
|
||||
expect(layer.style.transform).toBe("translate(50px, 105px) scale(1)");
|
||||
});
|
||||
|
||||
it("suppresses card navigation after a touch pan", async () => {
|
||||
const { viewport } = await renderOrgChart();
|
||||
const card = container.querySelector("[data-org-card]") as HTMLDivElement;
|
||||
|
||||
await act(async () => {
|
||||
viewport.dispatchEvent(createTouchEvent("touchstart", [{ clientX: 100, clientY: 100 }]));
|
||||
viewport.dispatchEvent(createTouchEvent("touchmove", [{ clientX: 130, clientY: 145 }]));
|
||||
viewport.dispatchEvent(createTouchEvent("touchend", []));
|
||||
card.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
||||
});
|
||||
|
||||
expect(navigateMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("allows card navigation after a touch tap without movement", async () => {
|
||||
const { viewport } = await renderOrgChart();
|
||||
const card = container.querySelector("[data-org-card]") as HTMLDivElement;
|
||||
|
||||
await act(async () => {
|
||||
viewport.dispatchEvent(createTouchEvent("touchstart", [{ clientX: 100, clientY: 100 }]));
|
||||
viewport.dispatchEvent(createTouchEvent("touchend", []));
|
||||
card.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
||||
});
|
||||
|
||||
expect(navigateMock).toHaveBeenCalledWith("/agents/ceo");
|
||||
});
|
||||
|
||||
it("pinch-zooms toward the touch center", async () => {
|
||||
const { viewport, layer } = await renderOrgChart();
|
||||
|
||||
|
||||
@@ -229,6 +229,15 @@ export function OrgChart() {
|
||||
moved: false,
|
||||
});
|
||||
const suppressNextCardClick = useRef(false);
|
||||
const suppressClickTimerRef = useRef<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (suppressClickTimerRef.current !== null) {
|
||||
window.clearTimeout(suppressClickTimerRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Center the chart on first load
|
||||
const hasInitialized = useRef(false);
|
||||
@@ -400,8 +409,12 @@ export function OrgChart() {
|
||||
const handleTouchEnd = useCallback(() => {
|
||||
if (touchGesture.current.moved) {
|
||||
suppressNextCardClick.current = true;
|
||||
window.setTimeout(() => {
|
||||
if (suppressClickTimerRef.current !== null) {
|
||||
window.clearTimeout(suppressClickTimerRef.current);
|
||||
}
|
||||
suppressClickTimerRef.current = window.setTimeout(() => {
|
||||
suppressNextCardClick.current = false;
|
||||
suppressClickTimerRef.current = null;
|
||||
}, 400);
|
||||
}
|
||||
touchGesture.current = {
|
||||
|
||||
Reference in new issue
Block a user