NorthwoodsSoftware / GoJS

JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.
http://gojs.net
Other
7.7k stars 2.86k forks source link

Context menu doesn't show in example #168

Closed keithpitt closed 2 years ago

keithpitt commented 2 years ago

Was browsing the examples, and it seems that the context menu doesn't show when you right click in the latest version of Safari. This was the example I was looking at: https://gojs.net/latest/samples/customContextMenu.html

Works fine in Chrome!

simonsarris commented 2 years ago

Thank you for reporting this. Luckily this is a bug in the sample code, not the library. In the sample, we add a "click" event listener:

    function showContextMenu(obj, diagram, tool) {

      ...

      // Optional: Use a `window` click listener with event capture to
      //           remove the context menu if the user clicks elsewhere on the page
      window.addEventListener("click", hideCX, true);
    }

    function hideContextMenu() {
      cxElement.classList.remove("show-menu");
      // Optional: Use a `window` click listener with event capture to
      //           remove the context menu if the user clicks elsewhere on the page
      window.removeEventListener("click", hideCX, true);
    }

Safari is firing that "click" event right after the context-click, as part of the context-click, and so it is showing the context menu and then immediately hiding it.

A simple fix would be to replace "click" with "pointerdown" so that it only happens on the next click/touch/etc. This is the edit to the sample we will release in the next version, and if you are using this sample code as a starting point you should make the same edit.