ContextMenu displays an overlay menu on right click of its target.
import { ContextMenuModule } from 'primeng/contextmenu';
ContextMenu can be attached to a particular element whose local template variable name is defined using the target property.
<img #img src="https://primefaces.org/cdn/primeng/images/demo/nature/nature3.jpg" alt="Logo" aria-haspopup="true" class="max-w-full">
<p-contextMenu [target]="img" [model]="items"></p-contextMenu>
Setting global property to true attaches the context menu to the document.
Right-Click anywhere on this page to view the global ContextMenu.
<p-contextMenu [model]="items" [global]="true"></p-contextMenu>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-contextmenu | Container element. |
p-menu-list | List element. |
p-menuitem | Menuitem element. |
p-menuitem-text | Label of a menuitem. |
p-menuitem-icon | Icon of a menuitem. |
p-submenu-icon | Arrow icon of a submenu. |
ContextMenu component uses the menubar role with aria-orientation set to "vertical" and the value to describe the menu can either be provided with aria-labelledby or aria-label props. Each list item has a presentation role whereas anchor elements have a menuitem role with aria-label referring to the label of the item and aria-disabled defined if the item is disabled. A submenu within a ContextMenu uses the menu role with an aria-labelledby defined as the id of the submenu root menuitem label. In addition, menuitems that open a submenu have aria-haspopup, aria-expanded and aria-controls to define the relation between the item and the submenu.
Key | Function |
---|---|
tab | When focus is in the menu, closes the context menu and moves focus to the next focusable element in the page sequence. |
enter | If menuitem has a submenu, toggles the visibility of the submenu otherwise activates the menuitem and closes all open overlays. |
space | If menuitem has a submenu, toggles the visibility of the submenu otherwise activates the menuitem and closes all open overlays. |
escape | Closes the context menu. |
down arrow | If focus is not inside the menu and menu is open, add focus to the first item. If an item is already focused, moves focus to the next menuitem within the submenu. |
up arrow | If focus is not inside the menu and menu is open, add focus to the last item. If an item is already focused, moves focus to the next menuitem within the submenu. |
right arrow | Opens a submenu if there is one available and moves focus to the first item. |
left arrow | Closes a submenu and moves focus to the root item of the closed submenu. |
home | Moves focus to the first menuitem within the submenu. |
end | Moves focus to the last menuitem within the submenu. |
API defines helper props, events and others for the PrimeNG ContextMenu module.
ContextMenu displays an overlay menu on right click of its target. Note that components like Table has special integration with ContextMenu.
Defines the input properties of the component.
name | type | default | description | ||
---|---|---|---|---|---|
MenuItem[] | |||||
string | |||||
string | HTMLElement | |||||
boolean | |||||
Object | |||||
string | |||||
any | |||||
boolean | |||||
number | |||||
string | |||||
string | |||||
string | |||||
number |
Defines emit that determine the behavior of the component based on a given condition or report the actions that the component takes.
name | parameters | description | |
---|---|---|---|
value : null | |||
value : null |
Defines the custom interfaces used by the module.
MenuItem provides the following properties. Note that not all of them may be utilized by the tabmenu component.
name | type | description |
---|---|---|
string | ||
string | ||
- | ||
string | ||
MenuItem[] | ||
boolean | ||
boolean | ||
boolean | ||
string | ||
boolean | ||
any | ||
boolean | ||
string | ||
string | ||
string | ||
string | ||
Object | ||
string | ||
string | ||
string | ||
any | ||
string | ||
any | ||
Object | ||
string | ||
QueryParamsHandling | ||
boolean | ||
boolean | ||
boolean | ||
Object | ||
string | ||
Object | ||
TooltipOptions |