Skip to content

Commit

Permalink
fix(hooks): do not add mouse and touch events in React native (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
silviuaavram authored Feb 21, 2023
1 parent 3046bea commit 694f2af
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function getHighlightedIndexOnOpen(props, state, offset) {
* @param {Function} handleBlur Handler on blur from mouse or touch.
* @returns {Object} Ref containing whether mouseDown or touchMove event is happening
*/
function useMouseAndTouchTracker(
function useMouseAndTouchTracker(
isOpen,
downshiftElementRefs,
environment,
Expand All @@ -317,6 +317,11 @@ function getHighlightedIndexOnOpen(props, state, offset) {
})

useEffect(() => {
/* istanbul ignore if (react-native) */
if (isReactNative) {
return
}

// The same strategy for checking if a click occurred inside or outside downsift
// as in downshift.js.
const onMouseDown = () => {
Expand Down Expand Up @@ -362,6 +367,7 @@ function getHighlightedIndexOnOpen(props, state, offset) {
environment.addEventListener('touchmove', onTouchMove)
environment.addEventListener('touchend', onTouchEnd)

// eslint-disable-next-line consistent-return
return function cleanup() {
environment.removeEventListener('mousedown', onMouseDown)
environment.removeEventListener('mouseup', onMouseUp)
Expand Down

0 comments on commit 694f2af

Please sign in to comment.