Articles in this section

How to include lengthy text in the context menu of a JavaScript Diagram?

This article explains how to include lengthy text in the context menu of a JavaScript diagram.

In a graphical user interface (GUI), the Context Menu, triggered by a right-click, enhances user interaction by providing specific actions related to the clicked item. When dealing with extensive textual content in the context menu, it is essential to ensure proper display without overlapping other menu items.

To incorporate lengthy text into a context menu item in a JavaScript Diagram, the contextMenuBeforeItemRender event can be utilized. This event allows customization before each context menu item is rendered, enabling adjustments to the appearance and behavior of menu items.

To prevent the overlap of long text with adjacent menu items, set the display property to content/inline for the specific context menu item. The diagram will automatically align and expand the width based on the size of the text content.

Consider the following code snippet as an example:

//Initialize the diagram    diagram = new ej.diagrams.Diagram({
      width: '100%'height: '645px'nodes: nodesconnectors: connections,    
      //Enables the context menu
      contextMenuSettings: {
        show: true,
        items: [
          {
            text: 'Cut  ',
            id: 'Cut',
            target: '.e-diagramcontent',
            iconCss: 'e-Cut',
          },
          {
            text: 'Copy  ',
            id: 'Copy',
            target: '.e-diagramcontent',
            iconCss: 'e-Copy',
          },
        ],
        // Hides the default context menu items
        showCustomMenuOnly: true,
      },
      contextMenuBeforeItemRender: contextMenuBeforeItemRender,
    });
   diagram.appendTo('#diagram');
    function contextMenuBeforeItemRender(args) {
        let shortCutSpan = document.createElement('span');
        let text = args.item.text;
        let shortCutText =
          text === 'Cut  '
            ? 'In graphical user interface (GUI), a context menu is a type of menu that appears when you perform right-click operation'
            : text === 'Copy  '
            ? 'Ctrl + U'
            : 'Ctrl + Shift + I';
        shortCutSpan.textContent = shortCutText;
        
        args.element.appendChild(shortCutSpan);
      
        shortCutSpan.setAttribute('class''shortcut');

      }
document.addEventListener('contextmenu', () => {
       
        const cut = document.getElementById('Cut');
        cut.style.display = 'contents';
});

Refer to the working sample for additional details and implementation: Sample on Stackblitz

 

Conclusion

We hope you enjoyed learning about how to Include lengthy text in the context menu of a JavaScript Diagram.


You can refer to our JavaScript Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Diagram example to understand how to create and manipulate data.


For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.


If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsBoldDesk Support, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied