Context Menu
- Dividers
- Checkable Menu Items
- Hierarchical Menu
- Tooltips
- Custom Items
- Styling Menu Items
- Disabled Menu Items
- Left-Click
- Custom Item Data
- Best Practices
- Related Components
Context Menu is a component that you can attach to any component to display a context menu. The menu appears on the right by default, or with a left click. On a touch device, a long press opens the context menu.
|
Important
| Open the Context Menu by right-clicking (i.e., with a mouse), or by long-pressing (i.e., on a touch screen), a Grid row. |
Source code
ContextMenuBasic.java
context-menu-basic.tsx
context-menu-basic.ts
Dividers
You can use dividers to separate and group related content. Use dividers sparingly to avoid creating unnecessary visual clutter.
|
Important
| Open the Context Menu by right-clicking (i.e., with a mouse), or by long-pressing (i.e., on a touch screen), a Grid row. |
Source code
ContextMenuDividers.java
context-menu-dividers.tsx
context-menu-dividers.ts
Checkable Menu Items
Checkable Menu Items can be used to toggle a setting on and off.
Source code
ContextMenuCheckable.java
context-menu-checkable.tsx
context-menu-checkable.ts
Hierarchical Menu
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.
|
Important
| Open the Context Menu by right-clicking (i.e., with a mouse), or by long-pressing (i.e., on a touch screen), a Grid row. |
Source code
ContextMenuHierarchical.java
context-menu-hierarchical.tsx
context-menu-hierarchical.ts
Tooltips
Menu items can be configured with tooltips to provide additional information.
Source code
ContextMenuTooltip.java
context-menu-tooltip.tsx
context-menu-tooltip.ts
See the Tooltips documentation page for details on tooltip configuration.
Tooltips are also useful on disabled menu items to explain why an action is unavailable, but they are not shown by default. See Disabled Menu Items for how to enable them.
Custom Items
You can customize the items to include more than a single line of text.
|
Important
| Open the Context Menu by right-clicking (i.e., with a mouse), or by long-pressing (i.e., on a touch screen), a Grid row. |
Source code
ContextMenuPresentation.java
person-item.css
person-item.css
context-menu-presentation.tsx
person-item.css
person-item.css
context-menu-presentation.ts
person-item.css
person-item.css
Styling Menu Items
Individual menu items can be styled by applying custom class names to them, and writing CSS style blocks targeting those class names.
Source code
ContextMenuClassname.java
context-menu-class-name.css
context-menu-class-name.css
context-menu-classname.tsx
context-menu-class-name.css
context-menu-class-name.css
context-menu-classname.ts
context-menu-class-name.css
context-menu-class-name.css
Disabled Menu Items
You can disable menu items to show that they are unavailable.
|
Important
| Open the Context Menu by right-clicking (i.e., with a mouse), or by long-pressing (i.e., on a touch screen), a Grid row. |
Source code
ContextMenuDisabled.java
context-menu-disabled.tsx
context-menu-disabled.ts
By default, disabled menu items aren’t focusable or hoverable, which hides them from assistive technologies and prevents Tooltips on disabled items from showing. The accessibleDisabledMenuItems feature flag can be enabled to make them focusable and hoverable without allowing them to be triggered:
Source code
Flow
Flow# Add this line to src/main/resources/vaadin-featureflags.properties
com.vaadin.experimental.accessibleDisabledMenuItems=trueLit & React
Lit & React// Set before any menu is added to the DOM
window.Vaadin.featureFlags.accessibleDisabledMenuItems = true;Disable on Click (Flow)
To prevent duplicate clicks while the server is processing a request, call the setDisableOnClick(true) method on a menu item instance to disable immediately that menu item on the client-side when it’s clicked.
Source code
ContextMenuDisableOnClick.java
Left-Click
You can use left-click to open Context Menu in situations where left-click doesn’t have any other function (e.g., a Grid without selection support).
|
Important
| Open the Context Menu by clicking a Grid row. |
Source code
ContextMenuLeftClick.java
context-menu-left-click.tsx
context-menu-left-click.ts
Custom Item Data
Context Menu allows you to associate custom data with menu items. This can be useful for storing additional information about the item, such as an item type or a value. The data can then be used to trigger actions when an item is selected.
Source code
ContextMenuCustomItemData.java
context-menu-custom-item-data.tsx
context-menu-custom-item-data.ts
Best Practices
Context Menu is used to provide shortcuts to the user. You shouldn’t use it as the only or primary means to complete a task. The primary way should be accessible elsewhere in the UI.
|
Important
| Open the Context Menu by right-clicking (i.e., for desktops) or long-pressing (i.e., for mobile devices) a Grid row, or use the Menu Bar in the last column. |
Source code
ContextMenuBestPractices.java
context-menu-best-practices.tsx
context-menu-best-practices.ts
Context Menu vs. Menu Bar
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 or component, such as an overflow menu, use Menu Bar.