Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Commit 0e4c8a7

Browse files
committed
fix: only stop onKeyDown propagation from menu when enter or escaped are pressed
Former-commit-id: 5ecd666
1 parent 9c1806b commit 0e4c8a7

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/react/loom-app/app/hooks/use-focus/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function useFocus() {
4343
if (focusableEls.length === 0) return;
4444

4545
focusNextElement(menuEl, focusableEls);
46-
} else if (isArrowKeyPressed(e, topMenu === null)) {
46+
} else if (isArrowKeyPressed(e, topMenu !== null)) {
4747
const layerEl = getTopMenuEl(topMenu, reactAppId);
4848
if (!layerEl) return;
4949

src/react/loom-app/app/hooks/use-focus/utils.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ export const getNumBottomBarFocusableEl = (appEl: HTMLElement) => {
8383

8484
export const isArrowKeyPressed = (
8585
e: React.KeyboardEvent,
86-
hasTopMenu: boolean
86+
isMenuOpen: boolean
8787
) => {
88-
if (hasTopMenu) {
89-
return (
90-
e.key === "ArrowDown" ||
91-
e.key === "ArrowUp" ||
92-
e.key === "ArrowLeft" ||
93-
e.key === "ArrowRight"
94-
);
88+
if (isMenuOpen) {
89+
return e.key === "ArrowDown" || e.key === "ArrowUp";
9590
}
96-
return e.key === "ArrowDown" || e.key === "ArrowUp";
91+
return (
92+
e.key === "ArrowDown" ||
93+
e.key === "ArrowUp" ||
94+
e.key === "ArrowLeft" ||
95+
e.key === "ArrowRight"
96+
);
9797
};

src/react/shared/menu/base-menu.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ const BaseMenu = React.forwardRef<HTMLDivElement, Props>(
4242
const logger = useLogger();
4343

4444
function handleKeyDown(e: React.KeyboardEvent) {
45-
//Don't propagate to the app
46-
e.stopPropagation();
47-
4845
logger("Menu handleKeyDown");
4946
if (e.key === "Enter") {
47+
//Don't propagate the enter event to the app
48+
//it will close all menus
49+
e.stopPropagation();
5050
onRequestClose("close-on-save");
5151
} else if (e.key === "Escape") {
52+
//Don't propagate the enter event to the app
53+
//it will close all menus
54+
e.stopPropagation();
5255
onClose();
5356
}
5457
}

0 commit comments

Comments
 (0)