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

onClick cannot be triggered using continuePropagation #6267

Open
Ciavarella opened this issue Apr 25, 2024 · 3 comments
Open

onClick cannot be triggered using continuePropagation #6267

Ciavarella opened this issue Apr 25, 2024 · 3 comments

Comments

@Ciavarella
Copy link

Provide a general summary of the issue here

onClick should be able to be triggered on parent but it is not, calling the e.continuePropagation does not change the parent onClick to be able to be triggered.

🤔 Expected Behavior?

onClick should be able to be triggered on parent

😯 Current Behavior

onClick is not triggered on parent when clicking a child onPress or onPressStart with continuePropagation.

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

https://codesandbox.io/p/sandbox/pensive-monad-vp8yp2?file=%2Fsrc%2FApp.js%3A25%2C17

Version

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Mac

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@sookmax
Copy link
Contributor

sookmax commented Apr 25, 2024

onClick is not triggered on parent when clicking a child onPress or onPressStart with continuePropagation.

As far as I can tell, only PressEvent handlers of the parent (a 'pressable' component, using usePress()) see the propagated event when PressEvent.continuePropagation() is called in the child (again, a 'pressable' component, using usePress()):

it('should allow propagation if continuePropagation is called', () => {
let outerPressMock = jest.fn();
let innerPressMock = jest.fn().mockImplementation(e => e.continuePropagation());
let res = render(
<Pressable
onPressStart={outerPressMock}
onPressEnd={outerPressMock}
onPress={outerPressMock}
onPressUp={outerPressMock}>
<Pressable
data-testid="test"
onPressStart={innerPressMock}
onPressEnd={innerPressMock}
onPress={innerPressMock}
onPressUp={innerPressMock}>
inner
</Pressable>
</Pressable>
);
let el = res.getByTestId('test');
start(el);
end(el);
expect(outerPressMock.mock.calls).toHaveLength(4);
expect(innerPressMock.mock.calls).toHaveLength(4);
});

The description of continuePropagation() also seems to say a similar thing:

/**
* By default, press events stop propagation to parent elements.
* In cases where a handler decides not to handle a specific event,
* it can call `continuePropagation()` to allow a parent to handle it.
*/
continuePropagation(): void

@Crustan
Copy link

Crustan commented Apr 26, 2024

onClick is not triggered on parent when clicking a child onPress or onPressStart with continuePropagation.

As far as I can tell, only PressEvent handlers of the parent (a 'pressable' component, using usePress()) see the propagated event when PressEvent.continuePropagation() is called in the child (again, a 'pressable' component, using usePress()):

This is a major issue since you might have third-party libraries that apply event listeners on wrapping components, that ain't a PressEvent (like MouseEvent), expecting the event to propagate.

Right now it's impossible to prevent the propagation from being stopped in those cases which totally breaks the other library, in our case, hotjar (https://help.hotjar.com/hc/en-us/articles/7053232973975-Heatmap-Data-Troubleshooting).

@staticshock
Copy link

staticshock commented May 1, 2024

Related: I'm seeing this in the context of a Checkbox, where a press (combined with continuePropagation) sometimes makes it through to the parent component when using tap-to-click on a trackpad, but not consistently. Tap-to-click the "Test" button a bunch of times here and eventually you'll see a state change:

https://codesandbox.io/p/sandbox/trusting-night-9q9824

Screen.Recording.2024-05-01.at.1.28.28.PM.mov

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

4 participants