Skip to content

Commit f7ec65e

Browse files
authored
[react-interactions] Make events non-passive to allow preventDefault (#17136)
1 parent 1022ee0 commit f7ec65e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,18 @@ const DEFAULT_PRESS_RETENTION_OFFSET = {
114114
};
115115

116116
const targetEventTypes = hasPointerEvents
117-
? ['keydown_active', 'pointerdown', 'click_active']
118-
: ['keydown_active', 'touchstart', 'mousedown', 'click_active'];
117+
? ['keydown_active', 'pointerdown_active', 'click_active']
118+
: ['keydown_active', 'touchstart', 'mousedown_active', 'click_active'];
119119

120120
const rootEventTypes = hasPointerEvents
121-
? ['pointerup', 'pointermove', 'pointercancel', 'click', 'keyup', 'scroll']
121+
? [
122+
'pointerup_active',
123+
'pointermove',
124+
'pointercancel',
125+
'click',
126+
'keyup',
127+
'scroll',
128+
]
122129
: [
123130
'click',
124131
'keyup',
@@ -128,7 +135,7 @@ const rootEventTypes = hasPointerEvents
128135
'touchcancel',
129136
// Used as a 'cancel' signal for mouse interactions
130137
'dragstart',
131-
'mouseup',
138+
'mouseup_active',
132139
'touchend',
133140
];
134141

packages/react-interactions/events/src/dom/__tests__/PressLegacy-test.internal.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,11 +1134,13 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => {
11341134

11351135
it('event.preventDefault works as expected', () => {
11361136
const onPress = jest.fn(e => e.preventDefault());
1137+
const onPressStart = jest.fn(e => e.preventDefault());
1138+
const onPressEnd = jest.fn(e => e.preventDefault());
11371139
const preventDefault = jest.fn();
11381140
const buttonRef = React.createRef();
11391141

11401142
const Component = () => {
1141-
const listener = usePress({onPress});
1143+
const listener = usePress({onPress, onPressStart, onPressEnd});
11421144
return <button ref={buttonRef} listeners={listener} />;
11431145
};
11441146
ReactDOM.render(<Component />, container);
@@ -1147,5 +1149,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => {
11471149
target.pointerdown();
11481150
target.pointerup({preventDefault});
11491151
expect(preventDefault).toBeCalled();
1152+
expect(onPressStart).toBeCalled();
1153+
expect(onPressEnd).toBeCalled();
11501154
});
11511155
});

0 commit comments

Comments
 (0)