A dynamic right-click menu for enhanced user interactions.
The JTB-Contextmenu is a dynamic component designed to provide custom context menus that appear when users right-click on a specified trigger element. It allows for a more interactive and intuitive user experience by offering context-specific actions and options directly at the point of interaction.
With its flexible structure and customizable items, the JTB-Contextmenu can be tailored to fit a variety of use cases, from simple action lists to complex nested menus, making it a valuable tool for enhancing user interfaces.
To create a JTB-Contextmenu in your projects, use the <jtb-contextmenu>
tag. This component is designed to display a custom context menu when a user right-clicks its trigger element. You can define menu items directly in HTML or populate them dynamically using JavaScript for enhanced flexibility.
To link a context menu to a trigger element, add the jtb-contextmenu
attribute to the trigger. The attribute value should be the ID of your context menu element. This setup ensures the menu appears at the cursor position upon right-click, providing a seamless user experience.
As demonstrated in the example above (adding items into contextmenus), you can customize the JTB-ContextMenu element by applying one (or more) of its pre-defined attributes with the corresponding values. These attributes allow you to tailor the element to meet your specific requirements and preferences via modifying the component's behavior, functionality, appearance, design etc.
To specify the items of context menu, use the element's data
attribute. The data
attribute should be an array that holds arrays (sections) which hold items as object where each object represents an item individually.
For each item, ensure that you've defined the content
parameter with the desired text you want to display in that item.
To use an icon in your items, simply set the icon
attribute with the identifier of your desired icon in your data.
As default, the icon template is set to: <i class='{icon}'></i>
where {icon}
serves as a placeholder that will be replaced by the value of the icon attribute.
Instead of using the default template, you can also specify your own custom template to generate icons exactly the way you want. Simply define your desired structure using the icon_template
attribute in your data elements, where {icon}
will be replaced by the value of the icon attribute.
To specify an action for an item to trigger on click, simply add your desired action to the action
attribute.
To simplify your workflow, we've created some pre-defined attributes for JTB-Contextmenu elements that enable you to customize their style and appearance with ease.
To change the shape of the container, use the shape
attribute with your desired value.
Available options are: default | rect
.
JTB Contextmenus are components built upon the jtbComponent
element. As a result, they inherit all global listeners and callbacks, ensuring consistent event handling. For a detailed overview, refer to the Base component - Core page.
Similar to listeners and callbacks, JTB Contextmenus also inherit all methods from the base component, enabling seamless functionality. For a complete list of available methods, visit the Base component - Core page.
While each property on its own brings unique changes to the elements, combining them can help you create the perfect one.
For making it easier to navigate through all the attributes, we’ve created a comprehensive table for you. Below, you can find a list of all and their uses.
Copyright © 2025 JTBLabs - All rights reserved.