I want my graph nodes not to be unselected when the user taps on the background.
From the docs of cytoscape.js I read
Gestures
Cytoscape.js supports several gestures:
- ...
- Tap background to unselect : desktop
- ...
All gesture actions can be controlled by the programmer, toggling them on or off whenever needed.
I however cannot find any option to toggle that gesture off. I tried to hook up the tap event and tried to cancel the event, but to no success.
cy.on('tab', ev => {
if (ev.target === cy) {
ev.preventDefault();
ev.originalEvent.preventDefault();
}
});
How to prevent unselection on tab background?
If anyone is still looking for a solution, I found this closed(answered) issue on the Cytoscape.js GitHub. Simon Golm's solution worked for me:
// Prevents the unselection of nodes when clicking on the background cy.on('click', (event) => { if (event.target === cy) { // click on the background cy.nodes().unselectify(); } else { cy.nodes().selectify(); } });