Documentation
Home Getting started References Layouts

Context menu example

Right click on the node to get a context menu


To add a context menu to the node add a contextMenu attribute to the nodes declarations, which contains an array of elements that you want in the context menu.

For example (showed on the graph):
                    
                        var nodes = [
                            { label: "Hello", contextMenu: ["Details", "More"] },
                            { label: "World" },
                            { label: "!" }
                    
                


You also need to define the event listener:
                    
                        canvas.addEventListener('contextmenu', function(e) {
                            /* write your code here*/
                    }
                    
                


And you have to add a html element for the context menu to be shown:
                    
                          <div id="context-menu" class="context-menu">
<ul id="context-menu__items" class="context-menu__items ">
</ul>
</div>


You can see the full code for this example here.