This repository was archived by the owner on Mar 9, 2025. It is now read-only.
File tree 3 files changed +16
-13
lines changed
loom-app/app/hooks/use-focus
3 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ export default function useFocus() {
43
43
if ( focusableEls . length === 0 ) return ;
44
44
45
45
focusNextElement ( menuEl , focusableEls ) ;
46
- } else if ( isArrowKeyPressed ( e , topMenu = == null ) ) {
46
+ } else if ( isArrowKeyPressed ( e , topMenu ! == null ) ) {
47
47
const layerEl = getTopMenuEl ( topMenu , reactAppId ) ;
48
48
if ( ! layerEl ) return ;
49
49
Original file line number Diff line number Diff line change @@ -83,15 +83,15 @@ export const getNumBottomBarFocusableEl = (appEl: HTMLElement) => {
83
83
84
84
export const isArrowKeyPressed = (
85
85
e : React . KeyboardEvent ,
86
- hasTopMenu : boolean
86
+ isMenuOpen : boolean
87
87
) => {
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" ;
95
90
}
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
+ ) ;
97
97
} ;
Original file line number Diff line number Diff line change @@ -42,13 +42,16 @@ const BaseMenu = React.forwardRef<HTMLDivElement, Props>(
42
42
const logger = useLogger ( ) ;
43
43
44
44
function handleKeyDown ( e : React . KeyboardEvent ) {
45
- //Don't propagate to the app
46
- e . stopPropagation ( ) ;
47
-
48
45
logger ( "Menu handleKeyDown" ) ;
49
46
if ( e . key === "Enter" ) {
47
+ //Don't propagate the enter event to the app
48
+ //it will close all menus
49
+ e . stopPropagation ( ) ;
50
50
onRequestClose ( "close-on-save" ) ;
51
51
} else if ( e . key === "Escape" ) {
52
+ //Don't propagate the enter event to the app
53
+ //it will close all menus
54
+ e . stopPropagation ( ) ;
52
55
onClose ( ) ;
53
56
}
54
57
}
You can’t perform that action at this time.
0 commit comments