Skip to content

Commit

Permalink
[dashboard] Ensure that context menus collapse even in Modals by not …
Browse files Browse the repository at this point in the history
…calling e.stopPropagation() on click events
  • Loading branch information
jankeromnes committed Aug 31, 2022
1 parent 82362cc commit 491c9fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 3 additions & 3 deletions components/dashboard/src/components/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function ContextMenu(props: ContextMenuProps) {
setExpanded(!expanded);
};

const handler = (evt: KeyboardEvent) => {
const keydownHandler = (evt: KeyboardEvent) => {
if (evt.key === "Escape") {
setExpanded(false);
}
Expand All @@ -55,11 +55,11 @@ function ContextMenu(props: ContextMenuProps) {
};

useEffect(() => {
window.addEventListener("keydown", handler);
window.addEventListener("keydown", keydownHandler);
window.addEventListener("click", clickHandler);
// Remove event listeners on cleanup
return () => {
window.removeEventListener("keydown", handler);
window.removeEventListener("keydown", keydownHandler);
window.removeEventListener("click", clickHandler);
};
}, []); // Empty array ensures that effect is only run on mount and unmount
Expand Down
1 change: 0 additions & 1 deletion components/dashboard/src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export default function Modal(props: {
"relative bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-800 rounded-xl p-6 max-w-lg mx-auto text-left " +
(props.className || "")
}
onClick={(e) => e.stopPropagation()}
>
{props.closeable !== false && (
<div
Expand Down

0 comments on commit 491c9fc

Please sign in to comment.