From 0a62c8ea92ae4c74544dcf2e9f25ad75213e30aa Mon Sep 17 00:00:00 2001 From: Marko Kosir Date: Wed, 30 Oct 2019 22:00:46 +0100 Subject: [PATCH] support 'touchstart' event --- package.json | 2 +- src/react-hook-mighty-mouse/types.ts | 2 +- src/react-hook-mighty-mouse/useMightyMouse.tsx | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 814d1da..72d3a8c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/react-hook-mighty-mouse/types.ts b/src/react-hook-mighty-mouse/types.ts index 49bc29e..e7d4d42 100644 --- a/src/react-hook-mighty-mouse/types.ts +++ b/src/react-hook-mighty-mouse/types.ts @@ -60,4 +60,4 @@ type SelectedElement = { isHover: boolean; }; -export type EventType = 'mousemove' | 'touchmove' | 'mousedown' | 'mouseup'; +export type EventType = 'mousemove' | 'mousedown' | 'mouseup' | 'touchmove' | 'touchstart'; diff --git a/src/react-hook-mighty-mouse/useMightyMouse.tsx b/src/react-hook-mighty-mouse/useMightyMouse.tsx index 5c40fd0..e32b1c8 100644 --- a/src/react-hook-mighty-mouse/useMightyMouse.tsx +++ b/src/react-hook-mighty-mouse/useMightyMouse.tsx @@ -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; @@ -164,6 +165,7 @@ const useMightyMouse = ( document.addEventListener('keyup', onKeyEvent); if (touchEnabled) { window.addEventListener('touchmove', onMouseTouchEvent); + window.addEventListener('touchstart', onMouseTouchEvent); window.addEventListener('touchend', onLeave); } @@ -176,6 +178,7 @@ const useMightyMouse = ( document.removeEventListener('keyup', onKeyEvent); if (touchEnabled) { window.removeEventListener('touchmove', onMouseTouchEvent); + window.removeEventListener('touchstart', onMouseTouchEvent); window.removeEventListener('touchend', onLeave); } };