Menu

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.

NameElement
p-menuContainer element.
p-menu-startContainer of the start slot.
p-menu-endContainer of the end slot.
p-menu-listList element.
p-submenu-headerHeader of the submenu list element.
p-menuitemMenuitem element.
p-menuitem-activeActive menuitem element.
p-menuitem-contentContent of menuitem.
p-menuitem-linkLink element of the menuitem.
p-menuitem-textLabel of a menuitem.
p-menuitem-iconIcon of a menuitem.

Screen Reader

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.

Keyboard Support

KeyFunction
tabAdd 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 + tabAdd 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.
enterActivates the focused menuitem. If menu is in overlay mode, popup gets closes and focus moves to target.
spaceActivates the focused menuitem. If menu is in overlay mode, popup gets closes and focus moves to target.
escapeIf menu is in overlay mode, popup gets closes and focus moves to target.
down arrowMoves focus to the next menuitem.
up arrowMoves focus to the previous menuitem.
alt + up arrowIf menu is in overlay mode, popup gets closes and focus moves to the target.
homeMoves focus to the first menuitem.
endMoves focus to the last menuitem.