Skip to content

Commit

Permalink
[dashboard] Close context menu when another one will be opened
Browse files Browse the repository at this point in the history
Fixes #3823
  • Loading branch information
corneliusludmann committed Jun 15, 2021
1 parent 1f5c6b1 commit 642c675
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions components/dashboard/src/components/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* See License-AGPL.txt in the project root for license information.
*/

import React from 'react';
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';

Expand Down Expand Up @@ -39,8 +40,17 @@ function ContextMenu(props: ContextMenuProps) {
}
}

const skipClickHandlerRef = React.useRef(false);
const setSkipClickHandler = (data: boolean) => {
skipClickHandlerRef.current = data;
}
const clickHandler = (evt: MouseEvent) => {
setExpanded(false);
if (skipClickHandlerRef.current) {
// skip only once
setSkipClickHandler(false);
} else {
setExpanded(false);
}
}

useEffect(() => {
Expand All @@ -65,7 +75,8 @@ function ContextMenu(props: ContextMenuProps) {
<div className="relative cursor-pointer">
<div onClick={(e) => {
toggleExpanded();
e.stopPropagation();
// Don't use `e.stopPropagation();` because that prevents that clicks on other context menus closes this one.
setSkipClickHandler(true);
}}>
{children}
</div>
Expand Down

0 comments on commit 642c675

Please sign in to comment.