Articles in this section

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

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

<DiagramComponent id="diagram" ref="{diagram" ==""> (diagramInstance = diagram)} 
       width={"100%"} height={"645px"} nodes={nodes} connectors={connections}
       contextMenuSettings={contextMenu}
       contextMenuBeforeItemRender={contextMenuBeforeItemRender}
>
 <Inject services={[UndoRedo, DiagramContextMenu]} />
</inject></DiagramComponent>

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

Conclusion

We hope you enjoyed learning about how to include lengthy text in the Context Menu of a React Diagram.

You can refer to our React Diagram feature tour page to learn about its other groundbreaking feature representations and documentation. You can also explore our React Diagram example to understand how to present 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 React Diagram and other components.

If you have any queries or require clarifications, please let us know in comments 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