Skip to content

Commit

Permalink
[react-interactions] Add no-op stopPropagation + preventDefault to Pr…
Browse files Browse the repository at this point in the history
…ess (#16868)

Fix
  • Loading branch information
trueadm authored Sep 23, 2019
1 parent 013b7ad commit 1758b3f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/react-interactions/events/src/dom/Press.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {PointerType} from 'shared/ReactDOMTypes';
import React from 'react';
import {useTap} from 'react-interactions/events/tap';
import {useKeyboard} from 'react-interactions/events/keyboard';
import warning from 'shared/warning';

const emptyObject = {};

Expand Down Expand Up @@ -48,6 +49,8 @@ type PressEvent = {|
type: PressEventType,
x: number,
y: number,
preventDefault: () => void,
stopPropagation: () => void,
|};

function createGestureState(e: any, type: PressEventType): PressEvent {
Expand All @@ -67,6 +70,26 @@ function createGestureState(e: any, type: PressEventType): PressEvent {
type,
x: e.x,
y: e.y,
preventDefault() {
// NO-OP, we should remove this in the future
if (__DEV__) {
warning(
false,
'preventDefault is not available on event objects created from event responder modules (React Flare). ' +
'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.preventDefault() }`',
);
}
},
stopPropagation() {
// NO-OP, we should remove this in the future
if (__DEV__) {
warning(
false,
'stopPropagation is not available on event objects created from event responder modules (React Flare). ' +
'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.stopPropagation() }`',
);
}
},
};
}

Expand Down
23 changes: 23 additions & 0 deletions packages/react-interactions/events/src/dom/PressLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {

import React from 'react';
import {DiscreteEvent, UserBlockingEvent} from 'shared/ReactTypes';
import warning from 'shared/warning';

type PressProps = {|
disabled: boolean,
Expand Down Expand Up @@ -93,6 +94,8 @@ type PressEvent = {|
type: PressEventType,
x: null | number,
y: null | number,
preventDefault: () => void,
stopPropagation: () => void,
|};

const hasPointerEvents =
Expand Down Expand Up @@ -185,6 +188,26 @@ function createPressEvent(
type,
x: clientX,
y: clientY,
preventDefault() {
// NO-OP, we should remove this in the future
if (__DEV__) {
warning(
false,
'preventDefault is not available on event objects created from event responder modules (React Flare). ' +
'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.preventDefault() }`',
);
}
},
stopPropagation() {
// NO-OP, we should remove this in the future
if (__DEV__) {
warning(
false,
'stopPropagation is not available on event objects created from event responder modules (React Flare). ' +
'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.stopPropagation() }`',
);
}
},
};
}

Expand Down

0 comments on commit 1758b3f

Please sign in to comment.