Show/Hide context menu for node

Hello! I am using go.HTMLInfo context Menu for a node.
I have functions Show and Hide.
Basically, it works perfectly. On right mouse click opens and closes on diagram click.
But I have a few modes in my diagram. The user moves between them by pressing buttons.
In each mode, the user sees a diagram.
There is one problem.
When the user is in one mode and open context menu for a node then he presses button and changes mode context menu is still open. I understand the user didn’t press the diagram so the context menu didn’t close.
I have to close it.
How I can call function hide from another React component?
I tried to use this .toolManager.contextMenuTool.hideContextMenu(); But it hides context menu forever.

Please guide me.

Yes, that is right – you need to call hideContextMenu on the Diagram’s ContextMenuTool.

At the time that the user wants to switch modes, don’t you have a reference to the Diagram?

Yes, I do have.
It the function I call
function toolHideContextMenu() {
diagramRef.current
.getDiagram()
.toolManager.contextMenuTool.hideContextMenu();
}

OK, so what is the problem?

It hides context menu forever. I can’t open it again.

I have different context menus for a node in different modes.

Ones I change the mode (and call hideContextMenu() ) I can’t open a context menu in new mode and if I go back to the first mode I also can’t open a context menu.

I need just close it but not to close forever

That’s odd. I’ll try it in one of our samples.

It turns out that hideContextMenu isn’t sufficient by itself. I suggest that you call this instead:

diagramRef.current.getDiagram().currentTool.doCancel();

or more generally, something like:

myDiagram.currentTool.doCancel();

It works. Thanks a lot!