Skip to content

Conversation

devongovett
Copy link
Member

Closes #2100

This adds a continuePropagation() method to PressEvent, like we have for keyboard events. This allows an onPressStart 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 an onPress 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 like onPress won't work, because by that point propagation will already have been stopped during onPressStart 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.

@rspbot
Copy link

rspbot commented Jun 19, 2023

return event.shouldStopPropagation;
}

return true;
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

@LFDanLu LFDanLu left a 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.

@rspbot
Copy link

rspbot commented Jun 28, 2023

@rspbot
Copy link

rspbot commented Jun 28, 2023

## API Changes

unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }

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.

onClick propagation with usePress

6 participants