Skip to content

Commit

Permalink
Fix: prevent clicks on entire document when dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 26, 2023
1 parent 895734e commit 4c1a8a3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export function makeDraggable(

const onPointerUp = () => {
if (isDragging) {
isDragging = false
onEnd?.()
}
unsubscribeDocument()
Expand All @@ -69,15 +68,15 @@ export function makeDraggable(
document.addEventListener('pointerup', onPointerUp)
document.addEventListener('pointercancel', onPointerUp)
document.addEventListener('touchmove', onTouchMove, { passive: false })
element.addEventListener('click', onClick, { capture: true })
document.addEventListener('click', onClick, { capture: true })

unsubscribeDocument = () => {
document.removeEventListener('pointermove', onPointerMove)
document.removeEventListener('pointerup', onPointerUp)
document.removeEventListener('pointercancel', onPointerUp)
document.removeEventListener('touchmove', onTouchMove)
setTimeout(() => {
element.removeEventListener('click', onClick, { capture: true })
document.removeEventListener('click', onClick, { capture: true })
}, 10)
}
}
Expand Down

0 comments on commit 4c1a8a3

Please sign in to comment.