Skip to content

Commit

Permalink
support 'touchstart' event
Browse files Browse the repository at this point in the history
  • Loading branch information
mkosir committed Oct 30, 2019
1 parent 31676be commit 0a62c8e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-hook-mighty-mouse",
"version": "1.4.23",
"version": "1.4.24",
"description": "React mouse hook",
"main": "./dist/react-hook-mighty-mouse.umd.js",
"module": "./dist/react-hook-mighty-mouse.es5.js",
Expand Down
2 changes: 1 addition & 1 deletion src/react-hook-mighty-mouse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ type SelectedElement = {
isHover: boolean;
};

export type EventType = 'mousemove' | 'touchmove' | 'mousedown' | 'mouseup';
export type EventType = 'mousemove' | 'mousedown' | 'mouseup' | 'touchmove' | 'touchstart';
3 changes: 3 additions & 0 deletions src/react-hook-mighty-mouse/useMightyMouse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const useMightyMouse = (
buttons.middle = [4, 5, 6, 7].indexOf(mouseEvent.buttons) > -1;
break;
case 'touchmove':
case 'touchstart':
const { touches } = event as TouchEvent;
const touchEvent = touches[0];
clientX = touchEvent.clientX;
Expand Down Expand Up @@ -164,6 +165,7 @@ const useMightyMouse = (
document.addEventListener('keyup', onKeyEvent);
if (touchEnabled) {
window.addEventListener('touchmove', onMouseTouchEvent);
window.addEventListener('touchstart', onMouseTouchEvent);
window.addEventListener('touchend', onLeave);
}

Expand All @@ -176,6 +178,7 @@ const useMightyMouse = (
document.removeEventListener('keyup', onKeyEvent);
if (touchEnabled) {
window.removeEventListener('touchmove', onMouseTouchEvent);
window.removeEventListener('touchstart', onMouseTouchEvent);
window.removeEventListener('touchend', onLeave);
}
};
Expand Down

0 comments on commit 0a62c8e

Please sign in to comment.