Articles in this section

How to include lengthy text in the Context Menu of a Angular Diagram?

This article explains how to include lengthy text in the context menu of an Angular 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 Angular 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:

<ejs-diagram #diagram id="diagram" width="100%" height="780px" [nodes]="nodes" [connectors]="connectors" [contextmenusettings]="contextMenuSettings" (contextMenuBeforeItemRender)="contextMenuBeforeItemRender($event)">
     </ejs-diagram> 
     

public contextMenuSettings: ContextMenuSettingsModel = {
   show: true, items: [
     {
       text: 'Cut  ',
       id: 'Cut',
       target: '.e-diagramcontent',
       iconCss: 'e-Cut',
     },
     {
       text: 'Copy  ',
       id: 'Copy',
       target: '.e-diagramcontent',
       iconCss: 'e-Copy',
     },],
   showCustomMenuOnly: true,
 };
 public contextMenuBeforeItemRender(args): void {
   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

Conclusion

We hope you enjoyed learning about how to include lengthy text in the context menu of an Angular diagram.

You can refer to our Angular Diagram feature tour page to learn about its other groundbreaking feature representations. You can explore our Angular Diagram documentation to understand how to present and manipulate data.

For current customers, you can check out our Angular 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 Angular Diagram and other Angular components. 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 forums, BoldDesk 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