MCPcopy Create free account
hub / github.com/adobe/react-spectrum / onKeyDown

Function onKeyDown

packages/react-aria/src/interactions/useContextMenu.ts:94–120  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

92 });
93 },
94 onKeyDown(e) {
95 // macOS has a default keyboard shortcut to show the contextmenu: Ctrl + Enter.
96 // However, some versions of Safari and Chrome do not trigger the contextmenu event.
97 // Fixed in https://github.com/WebKit/WebKit/pull/62278 (currently in WekKit nightly) and
98 // https://github.com/chromium/chromium/commit/268c876c191cd4712c2d1043aab9760fb71d9be5 (Chrome 147).
99 // Remove this workaround once those are broadly available.
100 // An additional bug still occurs when the target has a border-radius: https://bugs.webkit.org/show_bug.cgi?id=317496
101 if (isMac()) {
102 if (e.ctrlKey && e.key === 'Enter') {
103 firedContextMenuEvent.current = false;
104 let target = e.currentTarget;
105 e.stopPropagation();
106 setTimeout(() => {
107 if (!firedContextMenuEvent.current) {
108 let rect = target.getBoundingClientRect();
109 onContextMenu({
110 target,
111 x: rect.width / 2,
112 y: rect.height / 2
113 });
114 } else {
115 firedContextMenuEvent.current = false;
116 }
117 }, 10);
118 }
119 }
120 }
121 } satisfies HTMLAttributes<HTMLElement>)
122 };
123}

Callers

nothing calls this directly

Calls 1

onContextMenuFunction · 0.70

Tested by

no test coverage detected