Skip to content

Commit a449291

Browse files
Alex Danofffacebook-github-bot
authored andcommitted
Pressable: disable click bubbling in Pressable (facebook#37542)
Summary: Pull Request resolved: facebook#37542 Changelog: [General] [Changed] - Pressable: prevent click bubbling in Pressable This diff modifies pressability such that `onClick` events for pressables will only result in `onPress` being called when the pressable in question is both the `target` and the `currentTarget` for the event. This is only really relevant for nested pressables, where `click` received by the inner pressable may bubble up to the parent pressable (this change effectively prevents that from happening). A future change will update the click event on Android to be bubbling (currently its a direct event); this change will reduce the possibility of breakages from that change. Reviewed By: vincentriemer Differential Revision: D46081810 fbshipit-source-id: 37423fda03992d48baee04b753d7bb9295a76f9b
1 parent 40dbf19 commit a449291

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/react-native/Libraries/Pressability/Pressability.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,13 @@ export default class Pressability {
553553
return;
554554
}
555555

556+
// for non-pointer click events (e.g. accessibility clicks), we should only dispatch when we're the "real" target
557+
// in particular, we shouldn't respond to clicks from nested pressables
558+
if (event?.currentTarget !== event?.target) {
559+
event?.stopPropagation();
560+
return;
561+
}
562+
556563
const {onPress, disabled} = this._config;
557564
if (onPress != null && disabled !== true) {
558565
onPress(event);

0 commit comments

Comments
 (0)