@samitouri / QOS-React-2 / commits / d9fdec6cfe

[Flare] Remove contextmenu logic from Press (#16322)

Dominic Gannaway committed Aug 8, 2019 at 21:42 UTC d9fdec6cfec08f453be665c948e04a69467415da
2 files changed +1 -162
packages/react-events/src/dom/Press.js
+1 -39
@@ -28,10 +28,8 @@ type PressProps = {|
28 bottom: number,
29 left: number,
30 },
31 - preventContextMenu: boolean,
31 preventDefault: boolean,
32 stopPropagation: boolean,
34 - onContextMenu: (e: PressEvent) => void,
33 onPress: (e: PressEvent) => void,
34 onPressChange: boolean => void,
35 onPressEnd: (e: PressEvent) => void,
@@ -74,8 +72,7 @@ type PressEventType =
72 | 'pressmove'
73 | 'pressstart'
74 | 'pressend'
77 - | 'presschange'
78 - | 'contextmenu';
75 + | 'presschange';
76
77 type PressEvent = {|
78 button: 'primary' | 'auxillary',
@@ -111,7 +108,6 @@ const DEFAULT_PRESS_RETENTION_OFFSET = {
108
109 const targetEventTypes = [
110 'keydown_active',
114 - 'contextmenu_active',
111 // We need to preventDefault on pointerdown for mouse/pen events
112 // that are in hit target area but not the element area.
113 'pointerdown_active',
@@ -615,40 +611,6 @@ const pressResponderImpl = {
611 break;
612 }
613
618 - case 'contextmenu': {
619 - const preventContextMenu = props.preventContextMenu;
620 -
621 - if (preventContextMenu === true) {
622 - // Skip dispatching of onContextMenu below
623 - nativeEvent.preventDefault();
624 - }
625 -
626 - if (isPressed) {
627 - const preventDefault = props.preventDefault;
628 -
629 - if (preventDefault !== false && !nativeEvent.defaultPrevented) {
630 - // Skip dispatching of onContextMenu below
631 - nativeEvent.preventDefault();
632 - return;
633 - }
634 - dispatchCancel(event, context, props, state);
635 - }
636 - const onContextMenu = props.onContextMenu;
637 - if (isFunction(onContextMenu)) {
638 - dispatchEvent(
639 - event,
640 - onContextMenu,
641 - context,
642 - state,
643 - 'contextmenu',
644 - DiscreteEvent,
645 - );
646 - }
647 - // Click won't occur, so we need to remove root events
648 - removeRootEventTypes(context, state);
649 - break;
650 - }
651 -
614 case 'click': {
615 if (state.shouldPreventClick) {
616 nativeEvent.preventDefault();
packages/react-events/src/dom/__tests__/Press-test.internal.js
-123
@@ -2454,129 +2454,6 @@ describe('Event responder: Press', () => {
2454 },
2455 );
2456
2457 - describe('onContextMenu', () => {
2458 - it('is called after a right mouse click', () => {
2459 - const onContextMenu = jest.fn();
2460 - const ref = React.createRef();
2461 - const Component = () => {
2462 - const listener = usePressResponder({onContextMenu});
2463 -
2464 - return <div ref={ref} listeners={listener} />;
2465 - };
2466 - ReactDOM.render(<Component />, container);
2467 -
2468 - ref.current.dispatchEvent(
2469 - createEvent('pointerdown', {pointerType: 'mouse', button: 2}),
2470 - );
2471 - ref.current.dispatchEvent(createEvent('contextmenu'));
2472 - expect(onContextMenu).toHaveBeenCalledTimes(1);
2473 - expect(onContextMenu).toHaveBeenCalledWith(
2474 - expect.objectContaining({pointerType: 'mouse', type: 'contextmenu'}),
2475 - );
2476 - });
2477 -
2478 - it('is called after a left mouse click + ctrl key on Mac', () => {
2479 - jest.resetModules();
2480 - const platformGetter = jest.spyOn(global.navigator, 'platform', 'get');
2481 - platformGetter.mockReturnValue('MacIntel');
2482 - init();
2483 -
2484 - const onContextMenu = jest.fn();
2485 - const ref = React.createRef();
2486 -
2487 - const Component = () => {
2488 - const listener = usePressResponder({onContextMenu});
2489 -
2490 - return <div ref={ref} listeners={listener} />;
2491 - };
2492 - ReactDOM.render(<Component />, container);
2493 -
2494 - ref.current.dispatchEvent(
2495 - createEvent('pointerdown', {
2496 - pointerType: 'mouse',
2497 - button: 0,
2498 - ctrlKey: true,
2499 - }),
2500 - );
2501 - ref.current.dispatchEvent(createEvent('contextmenu'));
2502 - expect(onContextMenu).toHaveBeenCalledTimes(1);
2503 - expect(onContextMenu).toHaveBeenCalledWith(
2504 - expect.objectContaining({pointerType: 'mouse', type: 'contextmenu'}),
2505 - );
2506 - platformGetter.mockClear();
2507 - });
2508 -
2509 - it('is not called after a left mouse click + ctrl key on Windows', () => {
2510 - jest.resetModules();
2511 - const platformGetter = jest.spyOn(global.navigator, 'platform', 'get');
2512 - platformGetter.mockReturnValue('Win32');
2513 - init();
2514 -
2515 - const onContextMenu = jest.fn();
2516 - const ref = React.createRef();
2517 -
2518 - const Component = () => {
2519 - const listener = usePressResponder({onContextMenu});
2520 -
2521 - return <div ref={ref} listeners={listener} />;
2522 - };
2523 - ReactDOM.render(<Component />, container);
2524 -
2525 - ref.current.dispatchEvent(
2526 - createEvent('pointerdown', {
2527 - pointerType: 'mouse',
2528 - button: 0,
2529 - ctrlKey: true,
2530 - }),
2531 - );
2532 - ref.current.dispatchEvent(createEvent('contextmenu'));
2533 - expect(onContextMenu).toHaveBeenCalledTimes(0);
2534 - platformGetter.mockClear();
2535 - });
2536 -
2537 - it('is not called after a right mouse click occurs during an active press', () => {
2538 - const onContextMenu = jest.fn();
2539 - const ref = React.createRef();
2540 -
2541 - const Component = () => {
2542 - const listener = usePressResponder({onContextMenu});
2543 -
2544 - return <div ref={ref} listeners={listener} />;
2545 - };
2546 - ReactDOM.render(<Component />, container);
2547 -
2548 - ref.current.dispatchEvent(
2549 - createEvent('pointerdown', {pointerType: 'mouse', button: 0}),
2550 - );
2551 - ref.current.dispatchEvent(createEvent('contextmenu'));
2552 - expect(onContextMenu).toHaveBeenCalledTimes(0);
2553 - });
2554 -
2555 - it('is still called if "preventContextMenu" is true', () => {
2556 - const onContextMenu = jest.fn();
2557 - const ref = React.createRef();
2558 -
2559 - const Component = () => {
2560 - const listener = usePressResponder({
2561 - onContextMenu,
2562 - preventContextMenu: true,
2563 - });
2564 -
2565 - return <div ref={ref} listeners={listener} />;
2566 - };
2567 - ReactDOM.render(<Component />, container);
2568 -
2569 - ref.current.dispatchEvent(
2570 - createEvent('pointerdown', {pointerType: 'mouse', button: 2}),
2571 - );
2572 - ref.current.dispatchEvent(createEvent('contextmenu'));
2573 - expect(onContextMenu).toHaveBeenCalledTimes(1);
2574 - expect(onContextMenu).toHaveBeenCalledWith(
2575 - expect.objectContaining({defaultPrevented: true}),
2576 - );
2577 - });
2578 - });
2579 -
2457 it('should work correctly with stopPropagation set to true', () => {
2458 const ref = React.createRef();
2459 const pointerDownEvent = jest.fn();