Skip to content

Instantly share code, notes, and snippets.

@dr-skot
Last active July 31, 2022 18:10
Show Gist options
  • Save dr-skot/c70a82fb5c6467ba3e4eed3a60f781a1 to your computer and use it in GitHub Desktop.
Save dr-skot/c70a82fb5c6467ba3e4eed3a60f781a1 to your computer and use it in GitHub Desktop.
Suppress synthetic MouseMove event on touch
// 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