Hide Context Menu when we click outside diagram

I have a diagram and it has a context menu, I want the context menu to be hidden when we click the html components outside the diagram. Is there any way to achieve this?

That depends on the circumstances in which you want to remove any shown context menu.

So, depending on which event listeners you want to set up, what you want to do to remove any context menu is basically:

if (myDiagram.currentTool instanceof go.ContextMenuTool) {
  myDiagram.currentTool.doCancel();
}

Finally Worked!