mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-22 19:58:25 +08:00
[fix] Don't propagate click or contextmenu events on disabled elements
This patch fixes the PressResponder to avoid propagating click and contextmenu events in all circumstances. It also prevents click propagating for focusable elements that are disabled, mirroring the behavior of native buttons when disabled. Fix #1757
This commit is contained in:
@@ -388,8 +388,8 @@ export default class PressResponder {
|
||||
} else if (onPress != null && event.ctrlKey === false && event.altKey === false) {
|
||||
onPress(event);
|
||||
}
|
||||
event.stopPropagation();
|
||||
}
|
||||
event.stopPropagation();
|
||||
},
|
||||
|
||||
// If `onLongPress` is provided and a touch pointer is being used, prevent the
|
||||
@@ -399,6 +399,7 @@ export default class PressResponder {
|
||||
if (!disabled && onLongPress != null && this._isPointerTouch && !event.defaultPrevented) {
|
||||
event.preventDefault();
|
||||
}
|
||||
event.stopPropagation();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -229,7 +229,10 @@ const createDOMProps = (component, props) => {
|
||||
const onClick = domProps.onClick;
|
||||
if (onClick != null) {
|
||||
if (disabled) {
|
||||
domProps.onClick = undefined;
|
||||
// Prevent click propagating if the element is disabled. See #1757
|
||||
domProps.onClick = function(e) {
|
||||
e.stopPropagation();
|
||||
};
|
||||
} else if (!isNativeInteractiveElement) {
|
||||
// For native elements that are focusable but don't dispatch 'click' events
|
||||
// for keyboards.
|
||||
|
||||
Reference in New Issue
Block a user