Context menu doesn't show in example
keithpitt opened this issue · 1 comments
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!
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.