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

Supporting passive event listeners and preventDefault() #76

Closed
mpolichette opened this issue Jul 27, 2019 · 3 comments
Closed

Supporting passive event listeners and preventDefault() #76

mpolichette opened this issue Jul 27, 2019 · 3 comments

Comments

@mpolichette
Copy link
Contributor

mpolichette commented Jul 27, 2019

Hey guys, your project rocks.

I noticed that you support a config value for { event: { passive: true } }. However in the basic usage of useGesture (and others), your package doesn't actually do the event binding. So the event binding ends up not being passive except for the few global bindings (for drag).

I think this is fine and once you return the bindings its outside this packages scope.

The good news is that since you already support binding to external dom/refs, this issue is already resolved! Using the domTarget config will actually bring binding back into the hooks scope!

I fought this issue for a longer than I should have, and wish I'd have found an issue like this one while I was searching... So I'm creating it! :)

Feel free to close, but if we're looking for a resolution, I think we could add a note in the readme stating that the passive config value will only apply to most of your bindings if you use { domTarget: myRef } and React.useEffect(bind, [bind])

I could PR the issue to FAQ, but i'm not sure how F it is :)

@dbismut
Copy link
Collaborator

dbismut commented Jul 27, 2019

Hi @mpolichette, thanks for the kind words and reporting the issue. You're absolutely right. React doesn't support passive events (yet).

EDIT: actually I'm not even sure about this. It looks like touch events are treated passive by default...

EDIT2: this thread. At the end of the day, for clarity’s sake, maybe passive shouldn’t be an option except when domTarget is used and when we can actually control listeners behavior without worrying about React.

Feel free to add an item to the FAQ, might not be very frequent but it's been in the back of my head for a while, it would be great if it was clarified once and for all!

@mpolichette
Copy link
Contributor Author

I just pushed up a PR for the FAQ [#77]. You might be right about touch events, I ran into this for calling preventDefault on wheel events.

@dbismut
Copy link
Collaborator

dbismut commented Jul 29, 2019

That’s perfect! Thanks so much for this :)

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

No branches or pull requests

2 participants