Skip to content

Commit 2ef1bc7

Browse files
committed
[react-interactions] Add no-op stopPropagation + preventDefault to Press
Fix
1 parent 013b7ad commit 2ef1bc7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

packages/react-interactions/events/src/dom/Press.js

+23
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {PointerType} from 'shared/ReactDOMTypes';
1212
import React from 'react';
1313
import {useTap} from 'react-interactions/events/tap';
1414
import {useKeyboard} from 'react-interactions/events/keyboard';
15+
import warning from 'shared/warning';
1516

1617
const emptyObject = {};
1718

@@ -48,6 +49,8 @@ type PressEvent = {|
4849
type: PressEventType,
4950
x: number,
5051
y: number,
52+
preventDefault: () => void,
53+
stopPropagation: () => void,
5154
|};
5255

5356
function createGestureState(e: any, type: PressEventType): PressEvent {
@@ -67,6 +70,26 @@ function createGestureState(e: any, type: PressEventType): PressEvent {
6770
type,
6871
x: e.x,
6972
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+
},
7093
};
7194
}
7295

packages/react-interactions/events/src/dom/PressLegacy.js

+23
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919

2020
import React from 'react';
2121
import {DiscreteEvent, UserBlockingEvent} from 'shared/ReactTypes';
22+
import warning from 'shared/warning';
2223

2324
type PressProps = {|
2425
disabled: boolean,
@@ -93,6 +94,8 @@ type PressEvent = {|
9394
type: PressEventType,
9495
x: null | number,
9596
y: null | number,
97+
preventDefault: () => void,
98+
stopPropagation: () => void,
9699
|};
97100

98101
const hasPointerEvents =
@@ -185,6 +188,26 @@ function createPressEvent(
185188
type,
186189
x: clientX,
187190
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+
},
188211
};
189212
}
190213

0 commit comments

Comments
 (0)