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

attach listeners to parent element #164

Merged
merged 2 commits into from
Dec 10, 2019

Conversation

shelooks16
Copy link
Contributor

@shelooks16 shelooks16 commented Nov 28, 2019

  • package.json:version has been updated with npm version patch (or major/minor as appropriate)
  • @brainhubeu/react-carousel version has been updated in docs-www/package.json to the same which is in package.json:version

Attach listeners for simulated events to the carousel wrapper instead of window document

this.node.ownerDocument.addEventListener('touchstart', this.simulateEvent, true);
this.node.ownerDocument.addEventListener('touchmove', this.simulateEvent, { passive: false });
this.node.ownerDocument.addEventListener('touchend', this.simulateEvent, true);
this.node.parentElement.addEventListener('mousemove', this.onMouseMove, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this PR;
could you explain how this fixes the problem?
are you sure it's enough to add an event listener to only the parent element but not both to the parent element and the owner document?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The owner document references window.document. Simulating events globaly can potentially break other libraries which depend on those events/listeners. In my case, it was when I was using google maps. Why would I simulate touch events in a global context which can overlap with other libs? I want to keep it as local as possible.
Reference: https://stackoverflow.com/questions/9845043/when-node-ownerdocument-is-not-window-document

@piotr-s-brainhub
Copy link
Contributor

@Lukasz-pluszczewski

are you OK with this PR?

@piotr-s-brainhub piotr-s-brainhub merged commit 5f84333 into brainhubeu:master Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants