Last active
July 31, 2022 18:10
-
-
Save dr-skot/c70a82fb5c6467ba3e4eed3a60f781a1 to your computer and use it in GitHub Desktop.
Suppress synthetic MouseMove event on touch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// touch triggers both TouchStart and MouseMove events | |
// and not in a bubbling way -- both are thrown no matter how much you preventDefault() | |
// this suppresses the synthetic MouseMove event on touch | |
function onNonTouchMouseMove(mouseMoveHandler: MouseEventHandler<unknown>) { | |
let ignoreMouseMove = false; | |
return { | |
onTouchStart: () => { | |
ignoreMouseMove = true; | |
}, | |
onMouseMove: (event: MouseEvent<unknown>) => { | |
if (!ignoreMouseMove) mouseMoveHandler(event); | |
else ignoreMouseMove = false; | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment