A comprehensive guide for implementing Syncfusion TypeScript ContextMenu component. Use this skill when building context menus that appear on right-click or touch-hold, including features like nested menus, dynamic items, animations, events, styling, and data binding. This skill covers everything from basic setup to advanced features like scrolling, accessibility, and custom templates.
The ContextMenu is a graphical user interface component that appears on user right-click/touch-hold action. It provides support for nested menu items, custom templates, dynamic content, animations, and comprehensive event handling—making it ideal for building contextual actions in web applications.
📄 Read: references/getting-started.md
📄 Read: references/menu-structure.md
📄 Read: references/menu-items.md
📄 Read: references/interactions.md
📄 Read: references/styling.md
📄 Read: references/data-binding.md
📄 Read: references/advanced-features.md
📄 Read: references/api-reference.md
HTML:
<div>
<div id="contextmenutarget" style="border: 1px solid #ccc; padding: 20px; width: 300px; height: 200px;">
Right-click here to open the context menu
</div>
<ul id="contextmenu"></ul>
</div>
TypeScript:
import { ContextMenu } from '@syncfusion/ej2-navigations';
// Define menu items
const menuItems = [
{ text: 'Cut' },
{ text: 'Copy' },
{ text: 'Paste' },
{ separator: true },
{ text: 'Link' },
{ text: 'Share' }
];
// Initialize ContextMenu
const contextMenu = new ContextMenu({
items: menuItems,
target: '#contextmenutarget'
});
contextMenu.appendTo('#contextmenu');
const menuItems = [
{
text: 'Edit',
items: [
{ text: 'Cut' },
{ text: 'Copy' },
{ text: 'Paste' }
]
},
{
text: 'View',
items: [
{ text: 'Zoom In' },
{ text: 'Zoom Out' }
]
}
];
const contextMenu = new ContextMenu({
items: menuItems,
target: '#target'
});
const contextMenu = new ContextMenu({
items: menuItems,
target: '#target',
select: (args) => {
console.log('Selected: ' + args.item.text);
// Perform action based on selected item
}
});
// Add new items after initialization
const newItems = [{ text: 'New Option' }];
contextMenu.insertAfter(newItems, 'Edit');
const contextMenu = new ContextMenu({
items: menuItems,
target: '#target',
animationSettings: {
duration: 400,
easing: 'ease',
effect: 'SlideDown' // SlideDown, ZoomIn, FadeIn, etc.
}
});
const menuItems = [
{
text: 'Edit',
iconCss: 'e-icons e-edit'
},
{
text: 'Delete',
iconCss: 'e-icons e-delete'
},
{
text: 'External Link',
url: 'url'
}
];
| Property | Type | Purpose |
|---|---|---|
items | MenuItemModel[] | Menu items configuration |
target | string | CSS selector for triggering element |
animationSettings | MenuAnimationSettingsModel | Animation behavior |
cssClass | string | Custom CSS classes |
enableScrolling | boolean | Enable scrollbar for long menus |
enableRtl | boolean | Right-to-left layout support |
showItemOnClick | boolean | Submenu opens on click (vs hover) |
hoverDelay | number | Delay before submenu appears (ms) |
filter | string | CSS selector to filter target elements |
itemTemplate | string/Function | Custom template for menu items |