@samitouri / QOS-React-2 / commits / 1758b3f7ba

[react-interactions] Add no-op stopPropagation + preventDefault to Press (#16868)

Fix

Dominic Gannaway committed Sep 23, 2019 at 21:18 UTC 1758b3f7bafdb9197cf9464182f02da355f4c540
2 files changed +46
packages/react-interactions/events/src/dom/Press.js
+23
@@ -12,6 +12,7 @@ import type {PointerType} from 'shared/ReactDOMTypes';
12 import React from 'react';
13 import {useTap} from 'react-interactions/events/tap';
14 import {useKeyboard} from 'react-interactions/events/keyboard';
15 +import warning from 'shared/warning';
16
17 const emptyObject = {};
18
@@ -48,6 +49,8 @@ type PressEvent = {|
49 type: PressEventType,
50 x: number,
51 y: number,
52 + preventDefault: () => void,
53 + stopPropagation: () => void,
54 |};
55
56 function createGestureState(e: any, type: PressEventType): PressEvent {
@@ -67,6 +70,26 @@ function createGestureState(e: any, type: PressEventType): PressEvent {
70 type,
71 x: e.x,
72 y: e.y,
73 + preventDefault() {
74 + // NO-OP, we should remove this in the future
75 + if (__DEV__) {
76 + warning(
77 + false,
78 + 'preventDefault is not available on event objects created from event responder modules (React Flare). ' +
79 + 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.preventDefault() }`',
80 + );
81 + }
82 + },
83 + stopPropagation() {
84 + // NO-OP, we should remove this in the future
85 + if (__DEV__) {
86 + warning(
87 + false,
88 + 'stopPropagation is not available on event objects created from event responder modules (React Flare). ' +
89 + 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.stopPropagation() }`',
90 + );
91 + }
92 + },
93 };
94 }
95
packages/react-interactions/events/src/dom/PressLegacy.js
+23
@@ -19,6 +19,7 @@ import type {
19
20 import React from 'react';
21 import {DiscreteEvent, UserBlockingEvent} from 'shared/ReactTypes';
22 +import warning from 'shared/warning';
23
24 type PressProps = {|
25 disabled: boolean,
@@ -93,6 +94,8 @@ type PressEvent = {|
94 type: PressEventType,
95 x: null | number,
96 y: null | number,
97 + preventDefault: () => void,
98 + stopPropagation: () => void,
99 |};
100
101 const hasPointerEvents =
@@ -185,6 +188,26 @@ function createPressEvent(
188 type,
189 x: clientX,
190 y: clientY,
191 + preventDefault() {
192 + // NO-OP, we should remove this in the future
193 + if (__DEV__) {
194 + warning(
195 + false,
196 + 'preventDefault is not available on event objects created from event responder modules (React Flare). ' +
197 + 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.preventDefault() }`',
198 + );
199 + }
200 + },
201 + stopPropagation() {
202 + // NO-OP, we should remove this in the future
203 + if (__DEV__) {
204 + warning(
205 + false,
206 + 'stopPropagation is not available on event objects created from event responder modules (React Flare). ' +
207 + 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.stopPropagation() }`',
208 + );
209 + }
210 + },
211 };
212 }
213