Skip to content

Commit

Permalink
fix: normal click event running even after long press on ios
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Aug 16, 2023
1 parent 83aafbf commit ecb709e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/web/src/javascripts/Hooks/useLongPress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ export const useLongPressEvent = (
clearLongPressTimeout()
pointerPosition.current = { x: event.clientX, y: event.clientY }
longPressTimeout.current = window.setTimeout(() => {
elementRef.current?.addEventListener(
'mousedown',
(event) => {
event.preventDefault()
event.stopPropagation()
},
{ once: true, capture: true },
)

const x = event.clientX
const y = event.clientY

listener(x, y)
}, delay)
},
[clearLongPressTimeout, delay, listener],
[clearLongPressTimeout, delay, elementRef, listener],
)

const clearLongPressTimeoutIfMoved = useCallback(
Expand Down

0 comments on commit ecb709e

Please sign in to comment.