Skip to content

Commit d9fdec6

Browse files
authored
[Flare] Remove contextmenu logic from Press (#16322)
1 parent 12be893 commit d9fdec6

File tree

2 files changed

+1
-162
lines changed

2 files changed

+1
-162
lines changed

packages/react-events/src/dom/Press.js

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ type PressProps = {|
2828
bottom: number,
2929
left: number,
3030
},
31-
preventContextMenu: boolean,
3231
preventDefault: boolean,
3332
stopPropagation: boolean,
34-
onContextMenu: (e: PressEvent) => void,
3533
onPress: (e: PressEvent) => void,
3634
onPressChange: boolean => void,
3735
onPressEnd: (e: PressEvent) => void,
@@ -74,8 +72,7 @@ type PressEventType =
7472
| 'pressmove'
7573
| 'pressstart'
7674
| 'pressend'
77-
| 'presschange'
78-
| 'contextmenu';
75+
| 'presschange';
7976

8077
type PressEvent = {|
8178
button: 'primary' | 'auxillary',
@@ -111,7 +108,6 @@ const DEFAULT_PRESS_RETENTION_OFFSET = {
111108

112109
const targetEventTypes = [
113110
'keydown_active',
114-
'contextmenu_active',
115111
// We need to preventDefault on pointerdown for mouse/pen events
116112
// that are in hit target area but not the element area.
117113
'pointerdown_active',
@@ -615,40 +611,6 @@ const pressResponderImpl = {
615611
break;
616612
}
617613

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-
652614
case 'click': {
653615
if (state.shouldPreventClick) {
654616
nativeEvent.preventDefault();

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

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,129 +2454,6 @@ describe('Event responder: Press', () => {
24542454
},
24552455
);
24562456

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-
25802457
it('should work correctly with stopPropagation set to true', () => {
25812458
const ref = React.createRef();
25822459
const pointerDownEvent = jest.fn();

0 commit comments

Comments
 (0)