Menu is a navigation / command component that supports dynamic and static positioning.
import { MenuModule } from 'primeng/menu';
Menu requires a collection of menuitems as its model.
<p-menu [model]="items"></p-menu>
Menu supports one level of nesting by defining children with items property.
<p-toast></p-toast>
<p-menu [model]="items"></p-menu>
Popup mode is enabled by setting popup property to true and calling toggle method with an event of the target.
<p-toast></p-toast>
<p-menu #menu [model]="items" [popup]="true"></p-menu>
<button pButton type="button" (click)="menu.toggle($event)" icon="pi pi-bars" label="Show"></button>
Label of a menuitem both supports simple strings and html values as well. By default, html values are escaped, use escape property to allow html.
<p-menu [model]="items"></p-menu>
Navigation is specified using url property for external links and with routerLink for internal ones. If a menuitem has an active route, p-menuitem-link-active style class is added as an indicator. Active route link can be configured with routerLinkActiveOptions property of MenuItem API.
<p-menu [model]="items"></p-menu>
The function to invoke when an item is clicked is defined using the command property.
<p-toast></p-toast>
<p-menu [model]="items"></p-menu>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-menu | 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. |
Menu component uses the menu role 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 Menu uses the group role with an aria-labelledby defined as the id of the submenu root menuitem label.
In popup mode, the component implicitly manages the aria-expanded, aria-haspopup and aria-controls attributes of the target element to define the relation between the target and the popup.
Key | Function |
---|---|
tab | Add focus to the first item if focus moves in to the menu. If the focus is already within the menu, focus moves to the next focusable item in the page tab sequence. |
shift + tab | Add focus to the last item if focus moves in to the menu. If the focus is already within the menu, focus moves to the previous focusable item in the page tab sequence. |
enter | Activates the focused menuitem. If menu is in overlay mode, popup gets closes and focus moves to target. |
space | Activates the focused menuitem. If menu is in overlay mode, popup gets closes and focus moves to target. |
escape | If menu is in overlay mode, popup gets closes and focus moves to target. |
down arrow | Moves focus to the next menuitem. |
up arrow | Moves focus to the previous menuitem. |
home | Moves focus to the first menuitem. |
end | Moves focus to the last menuitem. |
API defines helper props, events and others for the PrimeNG Menu module.
Menu is a navigation / command component that supports dynamic and static positioning.
Defines the input properties of the component.
name | type | default | description | ||
---|---|---|---|---|---|
MenuItem[] | |||||
boolean | |||||
Object | |||||
string | |||||
any | |||||
boolean | |||||
number | |||||
string | |||||
string | |||||
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 : any | |||
value : any | |||
event : Event | |||
event : Event |
Defines methods that can be accessed by the component's reference.
name | parameters | description | |
---|---|---|---|
event : Event | |||
event : any | |||
- |
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 |