Class ContextMenu

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.contextmenu.ContextMenuBase<ContextMenu,MenuItem,SubMenu>
com.vaadin.flow.component.contextmenu.ContextMenu
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, HasMenuItems, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasStyle, HasOverlayClassName, Serializable

public class ContextMenu extends ContextMenuBase<ContextMenu,MenuItem,SubMenu> implements HasMenuItems, HasOverlayClassName
Context Menu is a component that you can attach to any component to display a context menu. The menu appears on right (default) or left click. On a touch device, a long press opens the context menu. You can use dividers to separate and group related content. Use dividers sparingly, though, to avoid creating unnecessary visual clutter.

Context Menu, like Menu Bar, supports multi-level sub-menus. You can use a hierarchical menu to organize a large set of options and group related items. Moreover, Context Menu supports checkable menu items that can be used to toggle a setting on and off. It also supports disabling menu items to show that they are unavailable. Menu items can also be customized to include more than a single line of text. You can use left-click to open Context Menu in situations where left-click does not have any other function, for example a Grid without selection support.

Best Practices:
Context Menu is used to provide shortcuts to the user. You should not use it as the only or primary means to complete a task. The primary way should be accessible elsewhere in the UI. Also note that you should use Context Menu when there is no dedicated button for opening an overlay menu, such as right-clicking a grid row. When there is a dedicated element/component, such as an overflow menu, use Menu Bar.

Author:
Vaadin Ltd.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase

    ContextMenuBase.OpenedChangeEvent<TComponent extends ContextMenuBase<TComponent,?,?>>
  • Field Summary

    Fields inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase

    EVENT_DETAIL
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty context menu.
    ContextMenu(com.vaadin.flow.component.Component target)
    Creates an empty context menu with the given target component.
  • Method Summary

    Modifier and Type
    Method
    Description
    addItem(com.vaadin.flow.component.Component component, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
    Adds a new item component with the given component and click listener to the context menu overlay.
    addItem(String text, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
    Adds a new item component with the given text content and click listener to the context menu overlay.
    createMenuManager(com.vaadin.flow.function.SerializableRunnable contentReset)
    Creates a menu manager instance which contains logic to control the menu content.

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasComponents

    add, add, addComponentAsFirst, remove

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.shared.HasOverlayClassName

    getOverlayClassName, setOverlayClassName

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName