Skip to content

Commit

Permalink
[react-interactions] Fix virtual click heuristic (#16915)
Browse files Browse the repository at this point in the history
  • Loading branch information
necolas authored Sep 27, 2019
1 parent f553515 commit d1121c0
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/react-interactions/events/src/dom/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit d1121c0

Please sign in to comment.