GoJS ContextMenu not working in Windows

GoJS context menu (using contextMenuTool.showContextMenu) is not coming up on right click on a OrgChart in Windows machines. I have noticed the same behavior in GoJS orgchart editor demo as well.
Can you please let me know if it is not supported in Windows OS? I am not facing any issues in Mac.

That isn’t the way to start the ContextMenuTool, which handles all of the events needed to handle context menus.

Instead, call CommandHandler | GoJS API to start showing the context menu for a specific GraphObject.

@walter This is what I am having. Enabling the menu based on a props and then applying some rules as well.
It would be helpful if you could share sample code / directions

$(go.Diagram, “orgChartDiv”,
{ initialContentAlignment: go.Spot.Left },
{ layout: $(go.TreeLayout, { layerSpacing: 30 }, { angle: 0 }) },
{
“contextMenuTool.showContextMenu”: function(cm, obj) {
// my code goes here
}
}

Also,

diagram.nodeTemplate = $(go.Node ,{
contextMenu: myProps ? $(“ContextMenu”) : null

Perhaps I misunderstood your situation. Why do you want to override ContextMenuTool.showContextMenu?

You have specified an empty menu. Did you want to modify that menu each time the menu is shown? If so, overriding ContextMenuTool.showContextMenu makes sense. Just be sure to call the super method after modifying the context menu.

However note that most context menus, such as those defined in the Basic sample, find it sufficient to show or hide each menu item based on the selected object or the current conditions.

The HTML Context Menu sample demonstrates modifying the context menu dynamically, but it uses HTML rather than GoJS "ContextMenuButton"s.

@walter Thank you for your response. I am calling go.ContextMenuTool.prototype.showContextMenu.call(this, cm, obj) at the end after building the context menu inside “contextMenuTool.showContextMenu”: function(cm, obj).

Everything working on Mac. But Windows machines the right click is not working and context menu is not coming up. Any inputs to fix this issue.

Are you using go-debug.js? Are you checking the console output for any warnings or errors?

You could please post (or send by email) what you are doing in your override of ContextMenuTool.showContextMenu?

@walter
I am not using go-debug.js. I have created a react component for OrgChart by requiring gojs.

if (process.env.BROWSER) {
go = require('gojs');
    go.licenseKey = "LICENSE KEY";
    $ = go.GraphObject.make;
}

There is no error or warning on right click. I think contextMenuTool.showContextMenu is not getting executed in Windows.

I am checking for some values in data object and based on that enabling context menu. Before adding the menu item, executing while (cm.elements.count > 0) cm.removeAt(0); to make sure there is no menu for the selected node. Then based on data, using cm.add($("ContextMenuButton", $(go.TextBlock, "My Menu Item"), { click: myFunction }

What you are doing seems perfectly reasonable. So I just tried this on Windows and Firefox. First the node template:

    myDiagram.nodeTemplate =
      $(go.Node, "Auto",
        {
          contextMenu: $("ContextMenu")
        },
        . . .

Second the override of ContextMenuTool.showContextMenu, following your code:

      $(go.Diagram, . . .,
          { . . .,
            "contextMenuTool.showContextMenu": function(cm, obj) {
              while (cm.elements.count > 0) cm.removeAt(0);
              var $ = go.GraphObject.make;
              cm.add($("ContextMenuButton", $(go.TextBlock, "first"), { click: function(e, button) { alert("first"); } }));
              cm.add($("ContextMenuButton", $(go.TextBlock, "second"), { click: function(e, button) { alert("second"); } }));
              go.ContextMenuTool.prototype.showContextMenu.call(this, cm, obj);
            }
          });

Everything worked as expected on the first try.

I’m still surprised that you are getting different results on different platforms. So you are probably right that there is some other platform-specific problem.

Also I hope you realize that when you construct the node template (Diagram.nodeTemplate) conditionally with or without a context menu, it means that all instances of nodes will either all have a context menu or none of them will. For each node data object in Model.nodeDataArray, it makes a copy of the node template and adds it to the Diagram.

So:

diagram.nodeTemplate = $(go.Node ,{
  contextMenu: myProps ? $(“ContextMenu”) : null,

you are deciding whether to include a $("ContextMenu") as the Node.contextMenu at the time that you are defining the node template. Not at the time the diagram is instantiating a node for the model’s node data object.

I assume this isn’t the problem because I assume you are making sure the value of myProps is the same on every platform/browser that you have tried, at the time that you are setting up the Diagram.