From 5c2acd886f7313af55c8e62145ecd2aaaad25835 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 8 Aug 2019 20:32:27 +0100 Subject: [PATCH] [Flare] Remove contextmenu logic from Press --- packages/react-events/src/dom/Press.js | 40 +----- .../src/dom/__tests__/Press-test.internal.js | 123 ------------------ 2 files changed, 1 insertion(+), 162 deletions(-) diff --git a/packages/react-events/src/dom/Press.js b/packages/react-events/src/dom/Press.js index e63ee0330eb74..aa39d91a35ca8 100644 --- a/packages/react-events/src/dom/Press.js +++ b/packages/react-events/src/dom/Press.js @@ -28,10 +28,8 @@ type PressProps = {| bottom: number, left: number, }, - preventContextMenu: boolean, preventDefault: boolean, stopPropagation: boolean, - onContextMenu: (e: PressEvent) => void, onPress: (e: PressEvent) => void, onPressChange: boolean => void, onPressEnd: (e: PressEvent) => void, @@ -74,8 +72,7 @@ type PressEventType = | 'pressmove' | 'pressstart' | 'pressend' - | 'presschange' - | 'contextmenu'; + | 'presschange'; type PressEvent = {| button: 'primary' | 'auxillary', @@ -111,7 +108,6 @@ const DEFAULT_PRESS_RETENTION_OFFSET = { const targetEventTypes = [ 'keydown_active', - 'contextmenu_active', // We need to preventDefault on pointerdown for mouse/pen events // that are in hit target area but not the element area. 'pointerdown_active', @@ -615,40 +611,6 @@ const pressResponderImpl = { break; } - case 'contextmenu': { - const preventContextMenu = props.preventContextMenu; - - if (preventContextMenu === true) { - // Skip dispatching of onContextMenu below - nativeEvent.preventDefault(); - } - - if (isPressed) { - const preventDefault = props.preventDefault; - - if (preventDefault !== false && !nativeEvent.defaultPrevented) { - // Skip dispatching of onContextMenu below - nativeEvent.preventDefault(); - return; - } - dispatchCancel(event, context, props, state); - } - const onContextMenu = props.onContextMenu; - if (isFunction(onContextMenu)) { - dispatchEvent( - event, - onContextMenu, - context, - state, - 'contextmenu', - DiscreteEvent, - ); - } - // Click won't occur, so we need to remove root events - removeRootEventTypes(context, state); - break; - } - case 'click': { if (state.shouldPreventClick) { nativeEvent.preventDefault(); diff --git a/packages/react-events/src/dom/__tests__/Press-test.internal.js b/packages/react-events/src/dom/__tests__/Press-test.internal.js index b60c59eafc1c5..de87adde0dc53 100644 --- a/packages/react-events/src/dom/__tests__/Press-test.internal.js +++ b/packages/react-events/src/dom/__tests__/Press-test.internal.js @@ -2454,129 +2454,6 @@ describe('Event responder: Press', () => { }, ); - describe('onContextMenu', () => { - it('is called after a right mouse click', () => { - const onContextMenu = jest.fn(); - const ref = React.createRef(); - const Component = () => { - const listener = usePressResponder({onContextMenu}); - - return
; - }; - ReactDOM.render(, container); - - ref.current.dispatchEvent( - createEvent('pointerdown', {pointerType: 'mouse', button: 2}), - ); - ref.current.dispatchEvent(createEvent('contextmenu')); - expect(onContextMenu).toHaveBeenCalledTimes(1); - expect(onContextMenu).toHaveBeenCalledWith( - expect.objectContaining({pointerType: 'mouse', type: 'contextmenu'}), - ); - }); - - it('is called after a left mouse click + ctrl key on Mac', () => { - jest.resetModules(); - const platformGetter = jest.spyOn(global.navigator, 'platform', 'get'); - platformGetter.mockReturnValue('MacIntel'); - init(); - - const onContextMenu = jest.fn(); - const ref = React.createRef(); - - const Component = () => { - const listener = usePressResponder({onContextMenu}); - - return
; - }; - ReactDOM.render(, container); - - ref.current.dispatchEvent( - createEvent('pointerdown', { - pointerType: 'mouse', - button: 0, - ctrlKey: true, - }), - ); - ref.current.dispatchEvent(createEvent('contextmenu')); - expect(onContextMenu).toHaveBeenCalledTimes(1); - expect(onContextMenu).toHaveBeenCalledWith( - expect.objectContaining({pointerType: 'mouse', type: 'contextmenu'}), - ); - platformGetter.mockClear(); - }); - - it('is not called after a left mouse click + ctrl key on Windows', () => { - jest.resetModules(); - const platformGetter = jest.spyOn(global.navigator, 'platform', 'get'); - platformGetter.mockReturnValue('Win32'); - init(); - - const onContextMenu = jest.fn(); - const ref = React.createRef(); - - const Component = () => { - const listener = usePressResponder({onContextMenu}); - - return
; - }; - ReactDOM.render(, container); - - ref.current.dispatchEvent( - createEvent('pointerdown', { - pointerType: 'mouse', - button: 0, - ctrlKey: true, - }), - ); - ref.current.dispatchEvent(createEvent('contextmenu')); - expect(onContextMenu).toHaveBeenCalledTimes(0); - platformGetter.mockClear(); - }); - - it('is not called after a right mouse click occurs during an active press', () => { - const onContextMenu = jest.fn(); - const ref = React.createRef(); - - const Component = () => { - const listener = usePressResponder({onContextMenu}); - - return
; - }; - ReactDOM.render(, container); - - ref.current.dispatchEvent( - createEvent('pointerdown', {pointerType: 'mouse', button: 0}), - ); - ref.current.dispatchEvent(createEvent('contextmenu')); - expect(onContextMenu).toHaveBeenCalledTimes(0); - }); - - it('is still called if "preventContextMenu" is true', () => { - const onContextMenu = jest.fn(); - const ref = React.createRef(); - - const Component = () => { - const listener = usePressResponder({ - onContextMenu, - preventContextMenu: true, - }); - - return
; - }; - ReactDOM.render(, container); - - ref.current.dispatchEvent( - createEvent('pointerdown', {pointerType: 'mouse', button: 2}), - ); - ref.current.dispatchEvent(createEvent('contextmenu')); - expect(onContextMenu).toHaveBeenCalledTimes(1); - expect(onContextMenu).toHaveBeenCalledWith( - expect.objectContaining({defaultPrevented: true}), - ); - }); - }); - it('should work correctly with stopPropagation set to true', () => { const ref = React.createRef(); const pointerDownEvent = jest.fn();