-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Provide a general summary of the issue here
In a certain case, onPress is sometimes firing onClick event handlers for elements beneath the target. This occurs when the onPress handler updates state which results in the component being unmounted.
🤔 Expected Behavior?
When using a touch device to press a react-aria-components Button (which usesusePress internally), it is expected that the Button will prevent propagation of that event.
This is usually the case as you can see below. In this case, we have two buttons. The top button is a react-aria-components Button using onPress. The element beneath is a standard HTML button with an onClick handler that fires an alert if clicked.
😯 Current Behavior
However, if the onPress handler results in the component being unmounted, the event sometimes propagates to the element beneath (seems to be inconsistent - maybe a race condition?).
Below is the same situation as before, but we conditionally render the react-aria-components Button based on React state, and in the onPress handler we toggle that state.
https://codesandbox.io/p/sandbox/suspicious-wilbur-k6v4l6
💁 Possible Solution
No response
🔦 Context
No response
🖥️ Steps to Reproduce
Code sandbox repro link: https://codesandbox.io/p/sandbox/suspicious-wilbur-k6v4l6
- Open Chrome dev tools and simulate a mobile device via device mode
- Tap the top button.
onPressEvent handler fires for top button, and top button is removed due to state update.onClickEvent handler fires for button underneath.
This might take a few tries as it is inconsistent.
Version
Latest react-aria-components 1.7.1
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
Mac OS 15.3.1
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response

