GeezerVison is showing github.com — [react-interactions] Fix virtual click heuristic (#16915) · react/react@d1121c0
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/react-interactions/events/src/dom/shared
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/react-interactions/events/src/dom/shared/index.js +7-10Lines changed: 7 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -71,16 +71,13 @@ export function hasModifierKey(event: ReactDOMResponderEvent): boolean { |
71 | 71 | ); |
72 | 72 | } |
73 | 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. |
77 | 80 | export function isVirtualClick(event: ReactDOMResponderEvent): boolean { |
78 | 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; |
86 | 83 | } |