onSwipedRight is firing when clicking outside the swipeable area
See original GitHub issueDescribe the bug
I have a swipeable area with the onSwipedLeft
and onSwipedRight
handlers. For some reason the onSwipedRight
event is firing if I click outside this area.
Steps or Sandbox to reproduce
- https://codesandbox.io/s/react-swipeable-bug-example-bllvn9?file=/src/index.js
- https://bllvn9.csb.app/
Steps to reproduce:
- Swipe the “swipe me” area
- Click the “click me” button, or the area above the “click me” button
- The
onSwipedRight
handler fires
Expected behavior
onSwipedRight
should not be firing if you click the button
Device/Browser Google Chrome 100.0.4896.88 (64-bit) (for desktop browser the bug is reproducing only in mobile device mode, for example iPhone XR) or Chrome for Android 98.0.4758.101; Android 10; Mi 9 Lite Build/QKQ1.190828.002
Additional context If you click on the swipeable area between step 1 and 2 the bug does not reproduce.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Click or tap through swipeable component · Issue #215 - GitHub
I want to use this package for opening a hamburger-menu with a swipe gesture, i defined a div with 30% width and a...
Read more >javascript - React, click outside event fire right after the open ...
I believe the event of the on click bubbles up, while the state is already toggled, and the ref is initialized, therefore at...
Read more >Creating An Outside Focus And Click Handler React Component
In this article, we'll look at how to create an outside focus and click handler with React. We will recreate an open source...
Read more >react-swipeable - Formidable Labs
A React swipe event handler hook. ... Edit react-swipeable image carousel ... After LEFT swipe (SwipeEventData) => void onSwipedRight, // After RIGHT swipe...
Read more >react-swipeable - npm
Start using react-swipeable in your project by running `npm i react-swipeable`. ... onSwipedRight, // Fired after RIGHT swipe.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@hartzis thank you as well for the explanation and fix. I really appreciate it!
@Sacret Okay this threw me through a bit of a loop, but after some exploration and strategically placed
debugger
’s the issue arises when bothtrackTouch
andtrackMouse
are utilized.We are attaching the
document
eventlisteners even if the swipe was started as a touch. So after a touch swipe happens themousemove
andmouseup
event listener’s are still attached and fire when you click outside the swipeable target. This “triggers” a new swipe based on the previous swipeseventData
🤦 .Now that i know what is happening there are a few solutions and clean ups we can do:
eventData
after a swipe “ends”mousemove
andmouseup
event listenersThank you thank you again @Sacret ! 🎉