From d1121c0174f541435b0619794410e0fb11774bd4 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Fri, 27 Sep 2019 15:38:47 -0700 Subject: [PATCH] [react-interactions] Fix virtual click heuristic (#16915) --- .../events/src/dom/shared/index.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/react-interactions/events/src/dom/shared/index.js b/packages/react-interactions/events/src/dom/shared/index.js index 681738442c0ab..92fb8b59321f5 100644 --- a/packages/react-interactions/events/src/dom/shared/index.js +++ b/packages/react-interactions/events/src/dom/shared/index.js @@ -71,16 +71,13 @@ export function hasModifierKey(event: ReactDOMResponderEvent): boolean { ); } -// Keyboards, Assitive Technologies, and element.click() all produce "virtual" -// clicks that do not include coordinates and "detail" is always 0 (where -// pointer clicks are > 0). +// Keyboards, Assitive Technologies, and element.click() all produce a "virtual" +// click event. This is a method of inferring such clicks. Every browser except +// IE 11 only sets a zero value of "detail" for click events that are "virtual". +// However, IE 11 uses a zero value for all click events. For IE 11 we rely on +// the quirk that it produces click events that are of type PointerEvent, and +// where only the "virtual" click lacks a pointerType field. export function isVirtualClick(event: ReactDOMResponderEvent): boolean { const nativeEvent: any = event.nativeEvent; - return ( - nativeEvent.detail === 0 && - nativeEvent.screenX === 0 && - nativeEvent.screenY === 0 && - nativeEvent.clientX === 0 && - nativeEvent.clientY === 0 - ); + return nativeEvent.detail === 0 && !nativeEvent.pointerType; }