mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[react-interactions] Make events non-passive to allow preventDefault (#17136)
This commit is contained in:
+11
-4
@@ -114,11 +114,18 @@ const DEFAULT_PRESS_RETENTION_OFFSET = {
|
||||
};
|
||||
|
||||
const targetEventTypes = hasPointerEvents
|
||||
? ['keydown_active', 'pointerdown', 'click_active']
|
||||
: ['keydown_active', 'touchstart', 'mousedown', 'click_active'];
|
||||
? ['keydown_active', 'pointerdown_active', 'click_active']
|
||||
: ['keydown_active', 'touchstart', 'mousedown_active', 'click_active'];
|
||||
|
||||
const rootEventTypes = hasPointerEvents
|
||||
? ['pointerup', 'pointermove', 'pointercancel', 'click', 'keyup', 'scroll']
|
||||
? [
|
||||
'pointerup_active',
|
||||
'pointermove',
|
||||
'pointercancel',
|
||||
'click',
|
||||
'keyup',
|
||||
'scroll',
|
||||
]
|
||||
: [
|
||||
'click',
|
||||
'keyup',
|
||||
@@ -128,7 +135,7 @@ const rootEventTypes = hasPointerEvents
|
||||
'touchcancel',
|
||||
// Used as a 'cancel' signal for mouse interactions
|
||||
'dragstart',
|
||||
'mouseup',
|
||||
'mouseup_active',
|
||||
'touchend',
|
||||
];
|
||||
|
||||
|
||||
@@ -1134,11 +1134,13 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => {
|
||||
|
||||
it('event.preventDefault works as expected', () => {
|
||||
const onPress = jest.fn(e => e.preventDefault());
|
||||
const onPressStart = jest.fn(e => e.preventDefault());
|
||||
const onPressEnd = jest.fn(e => e.preventDefault());
|
||||
const preventDefault = jest.fn();
|
||||
const buttonRef = React.createRef();
|
||||
|
||||
const Component = () => {
|
||||
const listener = usePress({onPress});
|
||||
const listener = usePress({onPress, onPressStart, onPressEnd});
|
||||
return <button ref={buttonRef} listeners={listener} />;
|
||||
};
|
||||
ReactDOM.render(<Component />, container);
|
||||
@@ -1147,5 +1149,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => {
|
||||
target.pointerdown();
|
||||
target.pointerup({preventDefault});
|
||||
expect(preventDefault).toBeCalled();
|
||||
expect(onPressStart).toBeCalled();
|
||||
expect(onPressEnd).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user