[react-interactions] Fix virtual click heuristic (#16915)
Nicolas Gallagher committed
Sep 27, 2019 at 15:38 UTC
d1121c0174f541435b0619794410e0fb11774bd4
1 file changed
+7
-10
packages/react-interactions/events/src/dom/shared/index.js
+7
-10
@@ -71,16 +71,13 @@ export function hasModifierKey(event: ReactDOMResponderEvent): boolean {
71
);
72
}
73
74
-// Keyboards, Assitive Technologies, and element.click() all produce "virtual"
75
-// clicks that do not include coordinates and "detail" is always 0 (where
76
-// pointer clicks are > 0).
74
+// Keyboards, Assitive Technologies, and element.click() all produce a "virtual"
75
+// click event. This is a method of inferring such clicks. Every browser except
76
+// IE 11 only sets a zero value of "detail" for click events that are "virtual".
77
+// However, IE 11 uses a zero value for all click events. For IE 11 we rely on
78
+// the quirk that it produces click events that are of type PointerEvent, and
79
+// where only the "virtual" click lacks a pointerType field.
80
export function isVirtualClick(event: ReactDOMResponderEvent): boolean {
81
const nativeEvent: any = event.nativeEvent;
79
- return (
80
- nativeEvent.detail === 0 &&
81
- nativeEvent.screenX === 0 &&
82
- nativeEvent.screenY === 0 &&
83
- nativeEvent.clientX === 0 &&
84
- nativeEvent.clientY === 0
85
- );
82
+ return nativeEvent.detail === 0 && !nativeEvent.pointerType;
83
}