-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for continuePropagation to usePress #4683
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
Conversation
Build successful! 🎉 |
return event.shouldStopPropagation; | ||
} | ||
|
||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have return values for these now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are called below and the return value is used to determine whether to stop propagation or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, tested locally and confirmed that longPress properly propagates the press to parent handlers on tap but not on actual long press. Only opinion is that it would be good to document the need to continuePropagation on pressStart and every subsequent press handler to actually propagate a press event, even if just in an "Advanced" section of the docs.
Build successful! 🎉 |
## API Changes
unknown top level export { type: 'identifier', name: 'Column' } |
Closes #2100
This adds a
continuePropagation()
method toPressEvent
, like we have for keyboard events. This allows anonPressStart
handler to decide that it won't handle a particular event (e.g. maybe a certain press handler only wants to handle touch events or something), and allow it to continue propagating to a parent element.A use case for this is in
useLongPress
, which shouldn't prevent a press event from occurring on a parent element if there is a long press handler on a child. If the user actually long presses, the pointer event will be canceled so anonPress
won't be called, but if the user doesn't press long enough, then parent press handlers should still work.One sorta weird thing about this is that
continuePropagation
only on an event likeonPress
won't work, because by that point propagation will already have been stopped duringonPressStart
so the press event won't actually reach the parent. So you'd kinda need to continuePropagation on all of them. We could maybe have a new prop to allow propagation, but then it would be harder to do it conditionally for only certain events (which feels like the main use case). I guess continuing propagation is already an advanced use case, so maybe this is fine? It matches our other hooks, and doesn't require adding any new props to lots of components.