Class ContextMenu
- All Implemented Interfaces:
AttachNotifier,HasMenuItems,DetachNotifier,HasElement,HasStyle,Serializable
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
ConstructorsConstructorDescriptionCreates an empty context menu.ContextMenu(Component target) Creates an empty context menu with the given target component. -
Method Summary
Modifier and TypeMethodDescriptionaddItem(Component component, ComponentEventListener<ClickEvent<MenuItem>> clickListener) Creates a new menu item with the given component content and click listener and adds it to the context menu overlay.addItem(String text, ComponentEventListener<ClickEvent<MenuItem>> clickListener) Creates a new menu item with the given text content and click listener and adds it to the context menu overlay.protected MenuManager<ContextMenu, MenuItem, SubMenu> createMenuManager(SerializableRunnable contentReset) Creates a menu manager instance which contains logic to control the menu content.Gets position of the context menu with respect to itstarget.voidsetPosition(ContextMenuPosition position) Sets position of the context menu with respect to its target.Methods inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase
addComponent, addComponent, addComponentAsFirst, addComponentAtIndex, addItem, addItem, addOpenedChangeListener, addSeparator, close, getChildren, getItems, getMenuManager, getTarget, isOpened, isOpenOnClick, onBeforeOpenMenu, remove, removeAll, setOpenOnClick, setTargetMethods 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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
ContextMenu
public ContextMenu()Creates an empty context menu. -
ContextMenu
Creates an empty context menu with the given target component.- Parameters:
target- the target component for this context menu- See Also:
-
-
Method Details
-
addItem
Description copied from interface:HasMenuItemsCreates a new menu item with the given text content and click listener and adds it to the context menu overlay.- Specified by:
addItemin interfaceHasMenuItems- Parameters:
text- the text content for the new itemclickListener- the handler for clicking the new item, can benullto not add listener- Returns:
- the added
MenuItemcomponent - See Also:
-
addItem
public MenuItem addItem(Component component, ComponentEventListener<ClickEvent<MenuItem>> clickListener) Description copied from interface:HasMenuItemsCreates a new menu item with the given component content and click listener and adds it to the context menu overlay.- Specified by:
addItemin interfaceHasMenuItems- Parameters:
component- the component inside the new itemclickListener- the handler for clicking the new item, can benullto not add listener- Returns:
- the added
MenuItemcomponent - See Also:
-
getPosition
Gets position of the context menu with respect to itstarget.- Returns:
- the position
-
createMenuManager
protected MenuManager<ContextMenu,MenuItem, createMenuManagerSubMenu> (SerializableRunnable contentReset) Description copied from class:ContextMenuBaseCreates a menu manager instance which contains logic to control the menu content.- Specified by:
createMenuManagerin classContextMenuBase<ContextMenu,MenuItem, SubMenu> - Parameters:
contentReset- callback to reset the menu content- Returns:
- a new menu manager instance
-