Menu

Menu displays a list of items in vertical orientation.


import Menu from 'primevue/menu';

Menu requires a collection of menuitems as its model.


<Menu :model="items" />

Menu supports single level of grouping by defining children with the items property.


<Menu :model="items" />

Overlay mode is enabled by adding popup property and calling toggle function of the menu ref with an event of the target.


<Button type="button" icon="pi pi-ellipsis-v" @click="toggle" aria-haspopup="true" aria-controls="overlay_menu" />
<Menu ref="menu" id="overlay_menu" :model="items" :popup="true" />

Menu offers item customization with the item template that receives the menuitem instance from the model as a parameter. The submenu header has its own submenuheader template, additional slots named start and end are provided to embed content before or after the menu.

PRIMEAPP

<Menu :model="items" class="w-full md:w-[17rem]">
    <template #start>
        <span class="inline-flex items-center gap-1 px-2 py-2 w-full sm:w-[15rem]">
            <svg width="35" height="40" viewBox="0 0 35 40" fill="none" xmlns="http://www.w3.org/2000/svg" class="h-[2rem]">
                <path d="..." class="fill-primary-500 dark:fill-primary-400" />
                <path d="..." class="fill-surface-700 dark:fill-surface-0/80" />
            </svg>
            <span class="font-medium text-xl">PRIME<span class="text-primary-500 dark:text-primary-400">APP</span></span>
        </span>
    </template>
    <template #submenuheader="{ item }">
        <span class="text-primary-500 dark:text-primary-400 font-bold leading-none">{{ item.label }}</span>
    </template>
    <template #item="{ item, props }">
        <a v-ripple class="flex items-center" v-bind="props.action">
            <span :class="item.icon" />
            <span class="ml-2">{{ item.label }}</span>
            <Badge v-if="item.badge" class="ml-auto" :value="item.badge" />
            <span v-if="item.shortcut" class="ml-auto border border-surface-200 dark:border-surface-700 rounded-md bg-surface-100 dark:bg-surface-700 text-xs p-1">{{ item.shortcut }}</span>
        </a>
    </template>
    <template #end>
        <button v-ripple class="relative overflow-hidden w-full p-link flex items-center p-2 pl-3 text-surface-700 dark:text-surface-0/80 hover:bg-surface-200 dark:hover:bg-surface-600 rounded-none">
            <Avatar image="/images/avatar/amyelsner.png" class="mr-2" shape="circle" />
            <span class="inline-flex flex-col justify-start">
                <span class="font-bold">Amy Elsner</span>
                <span class="text-sm">Admin</span>
            </span>
        </button>
    </template>
</Menu>

The command property defines the callback to run when an item is activated by click or a key event.


<Menu :model="items" />
<Toast />

Items with navigation are defined with templating to be able to use a router link component, an external link or programmatic navigation.


<Menu :model="items">
    <template #item="{ item, props }">
        <router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
            <a v-ripple :href="href" v-bind="props.action" @click="navigate">
                <span :class="item.icon" />
                <span class="ml-2">{{ item.label }}</span>
            </a>
        </router-link>
        <a v-else v-ripple :href="item.url" :target="item.target" v-bind="props.action">
            <span :class="item.icon" />
            <span class="ml-2">{{ item.label }}</span>
        </a>
    </template>
</Menu>

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.