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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
useDrag on a parent element triggering onClick for child elements #173
Comments
Hey @lourd thanks for the praise! Your challenge is not trivial, but I think there's a few ways we could address it, more or less elegantly. The main problem actually comes from the chronology between /* this doesn't work !! */
// useDrag logic
useDrag(
({ active }) => {
hasDragged.current = active
/* rest of the logic */
},
{ filterTaps: true }
)
// children click logic
<div onClick={ () => if(!hasDragged.current) alert('clicked', index) } />
// 1. user starts dragging -> hasDragged is true
// 2. user stops dragging
// 3. the children click handler fires but hasDragged is true so the logic doesn't run
// 4. useDrag sets hasDragged back to false Unfortunately,
Possible SolutionsThese possible solutions are not hard tested, you can explore each of them further! 1. Reset the
|
Holy cow @dbismut, this is gold! Your ultimate conclusion is brilliant, solves the problem absolutely perfectly. Bravo 馃憦馃憦 You were so helpful I gave $20 to the react-spring OpenCollective. Seriously, thank you! 馃檹 |
That鈥檚 really cool, much appreciated :) |
Btw, this will be the default in next version of react-use-gesture when setting |
That means a lot thank you @puckey |
This comment has been minimized.
This comment has been minimized.
I had a similar issue with |
Hey y'all,
Long time listener, first time caller 馃樃First off -- this library, and the other collection of react-spring libraries, are top-notch. It's so evident from using them that the authors care deeply about the excellence of their products and the tools they use to build them. The abstractions are good, the docs are thorough and clear (and beautiful!), and the examples are plentiful and up-to-date. Thank you all for the thought and effort that's gone into these projects 馃挋
I have a question about event capturing with
useDrag
. I'm making a prototype that needs to emulate touch scrolling on desktop. I've figured out how to do that, but have the issue where items within the scrolling have theironClick
handlers triggered when scrolling around. This makes sense, but I was wondering if y'all have pointers or ideas for workarounds. Hacky suggestions welcome, this is just a prototype.I made a demo of the challenge. The ideal behavior is that of typical mobile scrolling -- once a user starts scrolling the view by clicking and dragging (inadvertently on an element), releasing their finger/the mouse button while still over the element should not trigger onClick. As you can see from the demo, it is triggered.
I was hoping using
onClickCapture
for the child element in conjunction with theeventOptions.capture
option touseDrag
might work, but alas, it does not.Thanks in advance for any help you can offer 馃枛
The text was updated successfully, but these errors were encountered: