@@ -7,6 +7,7 @@ import { useLogger } from "src/shared/logger";
7
7
import { LoomMenuCloseRequestType , Position } from "./types" ;
8
8
9
9
import "./styles.css" ;
10
+ import { useMenuOperations } from "./hooks" ;
10
11
11
12
interface Props {
12
13
id : string ;
@@ -40,17 +41,27 @@ const BaseMenu = React.forwardRef<HTMLDivElement, Props>(
40
41
ref
41
42
) => {
42
43
const logger = useLogger ( ) ;
44
+ const { topMenu, onRequestCloseTop } = useMenuOperations ( ) ;
45
+
46
+ function handleClick ( e : React . MouseEvent ) {
47
+ logger ( "Menu handleClick" ) ;
48
+ //Don't propagate to the app
49
+ //it will close the menu again
50
+ e . stopPropagation ( ) ;
51
+ if ( topMenu . id === id ) return ;
52
+ onRequestCloseTop ( ) ;
53
+ }
43
54
44
55
function handleKeyDown ( e : React . KeyboardEvent ) {
45
56
logger ( "Menu handleKeyDown" ) ;
46
57
if ( e . key === "Enter" ) {
47
- //Don't propagate the enter event to the app
48
- //it will close all menus
58
+ //Don't propagate to the app
59
+ //it will close the menu again
49
60
e . stopPropagation ( ) ;
50
61
onRequestClose ( "close-on-save" ) ;
51
62
} else if ( e . key === "Escape" ) {
52
- //Don't propagate the enter event to the app
53
- //it will close all menus
63
+ //Don't propagate to the app
64
+ //it will close the menu again
54
65
e . stopPropagation ( ) ;
55
66
onClose ( ) ;
56
67
}
@@ -65,6 +76,7 @@ const BaseMenu = React.forwardRef<HTMLDivElement, Props>(
65
76
id = { id }
66
77
className = "dataloom-menu"
67
78
onKeyDown = { handleKeyDown }
79
+ onClick = { handleClick }
68
80
>
69
81
< div
70
82
ref = { ref }
0 commit comments