Skip to content
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

Propagation is not stopped for dynamically added items #7

Open
legomushroom opened this issue Oct 5, 2016 · 2 comments
Open

Propagation is not stopped for dynamically added items #7

legomushroom opened this issue Oct 5, 2016 · 2 comments

Comments

@legomushroom
Copy link

Hi, I'm working on react app (in fact preact but doesn't matter so much) and I add points inside of some plane(<div />). Points and the plane can be dragged independently with mouse pointer. So I have to stopPropagation on a point to prevent pan event propagate up to the plane and prevent it to be shifted too. So if I add a new point dynamically - stopPropagation doesn't work on newly added point. After refresh page - it works just fine.

I would happy to make live example, please just let me know if you still maintain this repo and I'll provide you reproduced issue.

@legomushroom
Copy link
Author

I found out that this line is the culprit:

/**
* Emit to the event listeners
* @param {string} eventType
* @param {Event} event
*/
wrapper.emit = function(eventType, event) {
  _firstTarget = event.target; // <------------------------------------- this one
  hammer.emit(eventType, event);
};

So you have this _firstTarget global and redefining it to event.target on each emit. Is there any reason for that? If I comment it - my issue gets solved, but I feel like it can break something?

Thanks in advance!

@josdejong
Copy link
Owner

josdejong commented Oct 5, 2016

Yes there was a very good reason for this _firstTarget, it ensures you keep the correct event target while dragging outside of the target where a drag started. Else you will not receive a drag end event for example when you stop dragging outside of the element where you started dragging. See this part of the code: https://github.com/josdejong/propagating-hammerjs/blob/master/propagating.js#L212-L226

Your issue with dynamically changed DOM is a generic one in react/preact, I've encountered it myself too. It's not specific to propagating-hammerjs. You can probably use event.stopPropagation() to prevent this, or maybe use a setTimeout(() => {...}, 0).

EDIT: I see now that you already tried event.stopPropagation. Maybe we can improve/fix stopPropagation to correctly deal with changed DOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants