Skip to content

Commit 09b126c

Browse files
committed
bug(web): Implement grid event move threshold
1 parent 51e1a0f commit 09b126c

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

packages/web/src/views/Calendar/hooks/grid/useGridEventMouseHold.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
import { Schema_GridEvent } from "@web/common/types/web.event.types";
88
import { getElemById } from "@web/common/utils/grid.util";
99

10-
const GRID_EVENT_MOUSE_HOLD_DELAY = 750;
10+
const GRID_EVENT_MOUSE_HOLD_DELAY = 750; // ms
11+
const GRID_EVENT_MOUSE_HOLD_MOVE_THRESHOLD = 25; // pixels
1112

1213
export const useGridEventMouseHold = (
1314
cb: (event: Schema_GridEvent) => void,
@@ -32,19 +33,31 @@ export const useGridEventMouseHold = (
3233
e.stopPropagation();
3334
mouseMoved.current = false;
3435

36+
const initialX = e.clientX;
37+
const initialY = e.clientY;
38+
3539
timeoutId.current = setTimeout(() => {
3640
if (!mouseMoved.current) {
3741
handleCallback(event);
3842
}
3943
}, delay);
4044

41-
const onMouseMove = () => {
42-
mouseMoved.current = true;
43-
if (timeoutId.current) {
44-
clearTimeout(timeoutId.current);
45+
const onMouseMove = (moveEvent: MouseEvent) => {
46+
// Calculate distance moved
47+
const deltaX = Math.abs(moveEvent.clientX - initialX);
48+
const deltaY = Math.abs(moveEvent.clientY - initialY);
49+
// Only count as moved if threshold is exceeded
50+
if (
51+
deltaX > GRID_EVENT_MOUSE_HOLD_MOVE_THRESHOLD ||
52+
deltaY > GRID_EVENT_MOUSE_HOLD_MOVE_THRESHOLD
53+
) {
54+
mouseMoved.current = true;
55+
if (timeoutId.current) {
56+
clearTimeout(timeoutId.current);
57+
}
58+
handleCallback(event);
59+
cleanup();
4560
}
46-
handleCallback(event);
47-
cleanup();
4861
};
4962

5063
const onMouseUp = () => {

0 commit comments

Comments
 (0)