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

Commit ac711f9

Browse files
committed
refactor: move menu click handler into Menu component
Former-commit-id: 39e1baa
1 parent 0e4c8a7 commit ac711f9

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/react/loom-app/app/index.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@ export default function App() {
132132
//Stop propagation to the global event
133133
e.stopPropagation();
134134

135-
//If we click on the top menu, don't close it
136-
const target = e.target as HTMLElement;
137-
const menuEl = target.closest(".dataloom-menu");
138-
if (menuEl) {
139-
const isTargetTopMenu = menuEl.id === topMenu.id;
140-
if (isTargetTopMenu) return;
141-
}
142-
143-
//Otherwise close the top menu
144135
onRequestCloseTop();
145136
}
146137

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useLogger } from "src/shared/logger";
77
import { LoomMenuCloseRequestType, Position } from "./types";
88

99
import "./styles.css";
10+
import { useMenuOperations } from "./hooks";
1011

1112
interface Props {
1213
id: string;
@@ -40,17 +41,27 @@ const BaseMenu = React.forwardRef<HTMLDivElement, Props>(
4041
ref
4142
) => {
4243
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+
}
4354

4455
function handleKeyDown(e: React.KeyboardEvent) {
4556
logger("Menu handleKeyDown");
4657
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
4960
e.stopPropagation();
5061
onRequestClose("close-on-save");
5162
} 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
5465
e.stopPropagation();
5566
onClose();
5667
}
@@ -65,6 +76,7 @@ const BaseMenu = React.forwardRef<HTMLDivElement, Props>(
6576
id={id}
6677
className="dataloom-menu"
6778
onKeyDown={handleKeyDown}
79+
onClick={handleClick}
6880
>
6981
<div
7082
ref={ref}

0 commit comments

Comments
 (0)