-
Notifications
You must be signed in to change notification settings - Fork 47.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
touchmove doesn't fire on removed element #1355
Comments
Is this in the DOM spec? It's kind of strange. |
Sorry, what's strange? Unlike mousemove, touchmove always fires on the element that received touchstart. In my limited testing, browsers happily send events to that removed element. |
You can test http://jsbin.com/gocuhifa/1 on device or in Chrome/Firefox with touch events enabled (touch down on "monkey"; it'll disappear; move your finger and you'll get an alert). |
Hmmmm maybe this isn't supposed to work: I sort of feel like it should still work in React just as well as it does in the browser though. |
See also the W3C public-webevents list where I asked about this behavior. |
This question is likely related: http://stackoverflow.com/q/24537000/49485. |
+1 |
Same problem :/ |
Optional solution: |
I believe in react this can be implemented manually with the user of |
I have been reading all the comments on this issue. So far, I understood that |
You are correct that when the div is removed from the DOM, its events will no longer bubble to the document and the onTouchMove handler will not fire. One solution to this problem is to bind the onTouchMove handler when the div receives a touchstart event, rather than delegating to the document. Here is an example of how you might do this: class MyComponent extends React.Component { ) ); } } In this example, when the div receives a touchstart event, the onTouchStart handler is called and it attaches the onTouchMove handler to the div element, so that it will fire when the user moves their finger. Additionally, it is important to remove the 'touchmove' event listener when the div is detached, to avoid memory leaks. This can be done by adding an onTouchEnd event that removes the 'touchmove' event listener. It's worth noting that this approach may not be ideal if you need to handle touchmove events on multiple elements, because you will have to attach and remove event listeners on each element individually. In this case, it might be more appropriate to use a library such as Hammer.js that is specifically designed for handling touch and gesture events in a more efficient and flexible way. |
If you have
such that the onTouchStart handler removes the div (and maybe replaces it with another one in the same place, useful in certain draggable interactions), the onTouchMove handler doesn't fire because the events of a detached element no longer bubble to document. We should probably bind the touchmove handler when the element receives touchstart instead of delegating to document.
Sort of related to #1254.
cc @Merbs @eater
The text was updated successfully, but these errors were encountered: