From ce5bbda3db315868097c4c61ec310bc913128bb6 Mon Sep 17 00:00:00 2001 From: Vadim Goy Date: Wed, 10 Mar 2021 17:17:18 +0200 Subject: [PATCH 1/2] fix scroll issues --- .../src/internal/useScrollCapture.js | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/react-select/src/internal/useScrollCapture.js b/packages/react-select/src/internal/useScrollCapture.js index 151e1e79ce..822c99fc13 100644 --- a/packages/react-select/src/internal/useScrollCapture.js +++ b/packages/react-select/src/internal/useScrollCapture.js @@ -96,6 +96,20 @@ export default function useScrollCapture({ }, [handleEventDelta] ); + const onMouseDown = useCallback( + (event: SyntheticMouseEvent) => { + // set mouse start so we can calculate mousemove delta + touchStart.current = event.clientY; + }, + [] + ); + const onMouseUp = useCallback( + (event: SyntheticMouseEvent) => { + const deltaY = event.clientY - touchStart.current; + handleEventDelta(event, deltaY); + }, + [handleEventDelta] + ); const startListening = useCallback( el => { @@ -113,8 +127,14 @@ export default function useScrollCapture({ if (typeof el.addEventListener === 'function') { el.addEventListener('touchmove', onTouchMove, notPassive); } + if (typeof el.addEventListener === 'function') { + el.addEventListener('mousedown', onMouseDown, notPassive); + } + if (typeof el.addEventListener === 'function') { + el.addEventListener('mouseup', onMouseUp, notPassive); + } }, - [onTouchMove, onTouchStart, onWheel] + [onTouchMove, onTouchStart, onWheel, onMouseDown, onMouseUp] ); const stopListening = useCallback( @@ -132,8 +152,14 @@ export default function useScrollCapture({ if (typeof el.removeEventListener === 'function') { el.removeEventListener('touchmove', onTouchMove, false); } + if (typeof el.removeEventListener === 'function') { + el.removeEventListener('mousedown', onMouseDown, false); + } + if (typeof el.removeEventListener === 'function') { + el.removeEventListener('mouseup', onMouseUp, false); + } }, - [onTouchMove, onTouchStart, onWheel] + [onTouchMove, onTouchStart, onWheel, onMouseDown, onMouseUp] ); useEffect(() => { From 4e10d6cb8f938f274abd1ef08e407ba40db24539 Mon Sep 17 00:00:00 2001 From: Vadim Goy Date: Wed, 10 Mar 2021 17:26:41 +0200 Subject: [PATCH 2/2] reformat code --- .../react-select/src/internal/useScrollCapture.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/react-select/src/internal/useScrollCapture.js b/packages/react-select/src/internal/useScrollCapture.js index 822c99fc13..d4a2c7598e 100644 --- a/packages/react-select/src/internal/useScrollCapture.js +++ b/packages/react-select/src/internal/useScrollCapture.js @@ -96,13 +96,10 @@ export default function useScrollCapture({ }, [handleEventDelta] ); - const onMouseDown = useCallback( - (event: SyntheticMouseEvent) => { - // set mouse start so we can calculate mousemove delta - touchStart.current = event.clientY; - }, - [] - ); + const onMouseDown = useCallback((event: SyntheticMouseEvent) => { + // set mouse start so we can calculate mousemove delta + touchStart.current = event.clientY; + }, []); const onMouseUp = useCallback( (event: SyntheticMouseEvent) => { const deltaY = event.clientY - touchStart.current;