[fix] only call preventDefault for clicks on links

The previous incarnation of this fix would cancel clicks that bubble up
to elements like ScrollViews, with undesired impact on child element
events. Instead, limit the hack to elements with accessibilityRole=link.

Fix #985
This commit is contained in:
Nicolas Gallagher
2018-06-05 09:02:35 -07:00
parent 6a310999d0
commit 5eeef9e3d2
@@ -50,6 +50,7 @@ const adjustProps = domProps => {
const isButtonRole = role === 'button'; const isButtonRole = role === 'button';
const isDisabled = AccessibilityUtil.isDisabled(domProps); const isDisabled = AccessibilityUtil.isDisabled(domProps);
const isLinkRole = role === 'link';
Object.keys(domProps).forEach(propName => { Object.keys(domProps).forEach(propName => {
const prop = domProps[propName]; const prop = domProps[propName];
@@ -67,11 +68,11 @@ const adjustProps = domProps => {
} }
}); });
// Cancel click events if the responder system is being used. Click events // Cancel click events if the responder system is being used on a link
// are not an expected part of the React Native API, and browsers dispatch // element. Click events are not an expected part of the React Native API,
// click events that cannot otherwise be cancelled from preceding mouse // and browsers dispatch click events that cannot otherwise be cancelled from
// events in the responder system. // preceding mouse events in the responder system.
if (onResponderRelease) { if (isLinkRole && onResponderRelease) {
domProps.onClick = function(e) { domProps.onClick = function(e) {
if (!e.isDefaultPrevented() && !isModifiedEvent(e.nativeEvent) && !domProps.target) { if (!e.isDefaultPrevented() && !isModifiedEvent(e.nativeEvent) && !domProps.target) {
e.preventDefault(); e.preventDefault();