I noticed that by default the GoJS canvas captures the mousedown event and does not let it pass to the element behind. But GoJS canvas allows the pointerdown event to pass through.
If you run the HTML below, when clicking on canvas, only “pointer down on body” is displayed in the console. But when you click below the canvas, both “pointer down on body” and “mouse down on body” are displayed.
I am wondering whether it is a bug or by design. I need a “global” event listener to detect user’s click event on the whole page with the GoJS canvas in it. And now I am using the pointerdown event handler. I just want to make sure that it is the correct approach.
Thanks for your time!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<div
id="myDiagramDiv"
style="border: solid 1px black; width: 100%; height: 70%"
></div>
<script src="../../release/go-debug.js"></script>
<script>
function init() {
const $ = go.GraphObject.make;
myDiagram = $(go.Diagram, "myDiagramDiv", {
layout: $(go.LayeredDigraphLayout),
});
myDiagram.click = e => (e.diagram.lastInput.bubbles = true);
}
window.addEventListener("DOMContentLoaded", init);
document.body.addEventListener("mousedown", () =>
console.log("mouse down on body"),
);
document.body.addEventListener("pointerdown", () =>
console.log("pointer down on body"),
);
</script>
</body>
</html>