documentationfor yFiles for HTML 2.6

ContextMenuInputMode

An implementation of the IInputMode interface that handles the display of a custom context menu when the user right clicks on the CanvasComponent.

Inheritance Hierarchy
ContextMenuInputMode
Implemented Interfaces

Remarks

This mode can be used with any context menu implementation since it does not impose any specific requirements. Typically, it is used in the following way.

First, this mode must be informed that the user wants to show the context menu with the method shouldOpenMenu, for example because a contextmenu event was fired.

Then, in response, this mode checks whether its current state allows opening a context menu, and fires the PopulateMenu and GraphInputMode.populateItemContextMenu.

If the context menu was closed because of user interaction with it, for example the user selected an menu entry, this mode must be informed by calling the method menuClosed.

This mode detects automatically if the menu must be closed because of other user interaction, for example the user clicked somewhere else, and fires the event CloseMenu to request closing of the context menu.

Examples

Typically the ContextMenuInputMode is installed as child mode of a GraphEditorInputMode or GraphViewerInputMode and can be retrieved from the contextMenuInputMode property.

Getting the ContextMenuInputMode from its parent input mode
const contextMenuInputMode = mode.contextMenuInputMode

It is recommended to configure the context menu handling on the parent GraphEditorInputMode or GraphViewerInputMode instead of the ContextMenuInputMode. This involves registering for the PopulateItemContextMenu event instead of the PopulateMenu event:

// mode is either an instance of GraphEditorInputMode or GraphViewerInputMode
mode.contextMenuItems = GraphItemTypes.NODE
mode.addPopulateItemContextMenuListener((sender, args) => {
  // Get the node which is handled or null if the item is not a node
  const node = args.item
  // Create the context menu items
  if (node !== null) {
    // Create a menu item to delete the node

    // Show the menu
    args.showMenu = true
    // Mark the event as handled
    args.handled = true
  }
})

Related Programming Samples

Context Menu
Shows how to add a context menu to the nodes of a graph and to the canvas background.

Type Details

yfiles module
view-component
yfiles-umd modules
All view modules
Legacy UMD name
yfiles.input.ContextMenuInputMode

See Also

For applications that are tailored towards touch input where you want support both, context menu and long-press gestures (e.g. edge creation), we recommend to lower the longPressTime value to (e.g.) 100ms because handling the context-menu event will stop other input modes from acting on the subsequent long-press event. Therefore lowering the longPressTime will extend the time frame between the long-press and the context-menu event.

Constructors

Properties

Methods

Events