Menu is a navigation/command component that supports dynamic and static positioning.
import Menu from 'primevue/menu';
Menu requires a collection of menuitems as its model.
<Menu :model="items" />
Menu supports one level of nesting by defining children with items property.
<Menu :model="items" />
<Toast />
Popup mode is enabled by adding popup property and calling toggle method with an event of the target.
<Button type="button" label="Toggle" @click="toggle" aria-haspopup="true" aria-controls="overlay_menu" />
<Menu ref="menu" id="overlay_menu" :model="items" :popup="true" />
<Toast />
Two slots named "start" and "end" are provided to embed content before or after the menu. In additon Menu, offers item customization with the item template that receives the menuitem instance from the model as a parameter.
<Menu :model="items">
<template #start>
<button @click="profileClick" class="w-full p-link flex align-items-center p-2 pl-3 text-color hover:surface-200 border-noround">
<Avatar image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" class="mr-2" shape="circle" />
<div class="flex flex-column align">
<span class="font-bold">Amy Elsner</span>
<span class="text-sm">Agent</span>
</div>
</button>
</template>
<template #end>
<button class="w-full p-link flex align-items-center p-2 pl-4 text-color hover:surface-200 border-noround">
<i class="pi pi-sign-out" />
<span class="ml-2">Log Out</span>
</button>
</template>
</Menu>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-menu | Container element. |
p-menu-start | Container of the start slot. |
p-menu-end | Container of the end slot. |
p-menu-list | List element. |
p-submenu-header | Header of the submenu list element. |
p-menuitem | Menuitem element. |
p-menuitem-active | Active menuitem element. |
p-menuitem-content | Content of menuitem. |
p-menuitem-link | Link element of the menuitem. |
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 menuitem role with aria-label referring to the label of the item and aria-disabled defined if the item is disabled.
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 first 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. |
alt + up arrow | If menu is in overlay mode, popup gets closes and focus moves to the target. |
home | Moves focus to the first menuitem. |
end | Moves focus to the last menuitem. |