Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/downshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,21 +1133,23 @@ class Downshift extends Component {
}
const {environment} = this.props

environment.addEventListener('mousedown', onMouseDown)
environment.addEventListener('mouseup', onMouseUp)
environment.addEventListener('touchstart', onTouchStart)
environment.addEventListener('touchmove', onTouchMove)
environment.addEventListener('touchend', onTouchEnd)
const options = {passive: true}

environment.addEventListener('mousedown', onMouseDown, options)
environment.addEventListener('mouseup', onMouseUp, options)
environment.addEventListener('touchstart', onTouchStart, options)
environment.addEventListener('touchmove', onTouchMove, options)
environment.addEventListener('touchend', onTouchEnd, options)

this.cleanup = () => {
this.internalClearTimeouts()
this.updateStatus.cancel()

environment.removeEventListener('mousedown', onMouseDown)
environment.removeEventListener('mouseup', onMouseUp)
environment.removeEventListener('touchstart', onTouchStart)
environment.removeEventListener('touchmove', onTouchMove)
environment.removeEventListener('touchend', onTouchEnd)
environment.removeEventListener('mousedown', onMouseDown, options)
environment.removeEventListener('mouseup', onMouseUp, options)
environment.removeEventListener('touchstart', onTouchStart, options)
environment.removeEventListener('touchmove', onTouchMove, options)
environment.removeEventListener('touchend', onTouchEnd, options)
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/hooks/__tests__/__snapshots__/utils.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@ exports[`utils useMouseAndTouchTracker adds and removes listeners to environment
[
mousedown,
[Function],
{
passive: true,
},
],
[
mouseup,
[Function],
{
passive: true,
},
],
[
touchstart,
[Function],
{
passive: true,
},
],
[
touchmove,
[Function],
{
passive: true,
},
],
[
touchend,
[Function],
{
passive: true,
},
],
]
`;
Expand All @@ -30,22 +45,37 @@ exports[`utils useMouseAndTouchTracker adds and removes listeners to environment
[
mousedown,
[Function],
{
passive: true,
},
],
[
mouseup,
[Function],
{
passive: true,
},
],
[
touchstart,
[Function],
{
passive: true,
},
],
[
touchmove,
[Function],
{
passive: true,
},
],
[
touchend,
[Function],
{
passive: true,
},
],
]
`;
Expand All @@ -55,22 +85,37 @@ exports[`utils useMouseAndTouchTracker adds and removes listeners to environment
[
mousedown,
[Function],
{
passive: true,
},
],
[
mouseup,
[Function],
{
passive: true,
},
],
[
touchstart,
[Function],
{
passive: true,
},
],
[
touchmove,
[Function],
{
passive: true,
},
],
[
touchend,
[Function],
{
passive: true,
},
],
]
`;
Expand All @@ -80,22 +125,37 @@ exports[`utils useMouseAndTouchTracker adds and removes listeners to environment
[
mousedown,
[Function],
{
passive: true,
},
],
[
mouseup,
[Function],
{
passive: true,
},
],
[
touchstart,
[Function],
{
passive: true,
},
],
[
touchmove,
[Function],
{
passive: true,
},
],
[
touchend,
[Function],
{
passive: true,
},
],
]
`;
22 changes: 12 additions & 10 deletions src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,20 @@ function useMouseAndTouchTracker(
}
}

environment.addEventListener('mousedown', onMouseDown)
environment.addEventListener('mouseup', onMouseUp)
environment.addEventListener('touchstart', onTouchStart)
environment.addEventListener('touchmove', onTouchMove)
environment.addEventListener('touchend', onTouchEnd)
const options = {passive: true}

environment.addEventListener('mousedown', onMouseDown, options)
environment.addEventListener('mouseup', onMouseUp, options)
environment.addEventListener('touchstart', onTouchStart, options)
environment.addEventListener('touchmove', onTouchMove, options)
environment.addEventListener('touchend', onTouchEnd, options)

return function cleanup() {
environment.removeEventListener('mousedown', onMouseDown)
environment.removeEventListener('mouseup', onMouseUp)
environment.removeEventListener('touchstart', onTouchStart)
environment.removeEventListener('touchmove', onTouchMove)
environment.removeEventListener('touchend', onTouchEnd)
environment.removeEventListener('mousedown', onMouseDown, options)
environment.removeEventListener('mouseup', onMouseUp, options)
environment.removeEventListener('touchstart', onTouchStart, options)
environment.removeEventListener('touchmove', onTouchMove, options)
environment.removeEventListener('touchend', onTouchEnd, options)
}
}, [downshiftElementsRefs, environment, handleBlur])

Expand Down