import MegaMenu from 'primevue/megamenu';
<script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>
<script src="https://unpkg.com/primevue@^3/megamenu/megamenu.min.js"></script>
MegaMenu uses the common MenuModel API to define the items of the model, visit
<MegaMenu :model="items" />
export default {
data() {
return {
items: [
{
label: 'Videos', icon: 'pi pi-fw pi-video',
items: [
[
{
label: 'Video 1',
items: [{label: 'Video 1.1'}, {label: 'Video 1.2'}]
},
{
label: 'Video 2',
items: [{label: 'Video 2.1'}, {label: 'Video 2.2'}]
}
],
[
{
label: 'Video 3',
items: [{label: 'Video 3.1'}, {label: 'Video 3.2'}]
},
{
label: 'Video 4',
items: [{label: 'Video 4.1'}, {label: 'Video 4.2'}]
}
]
]
},
{
label: 'Users', icon: 'pi pi-fw pi-users',
items: [
[
{
label: 'User 1',
items: [{label: 'User 1.1'}, {label: 'User 1.2'}]
},
{
label: 'User 2',
items: [{label: 'User 2.1'}, {label: 'User 2.2'}]
},
],
[
{
label: 'User 3',
items: [{label: 'User 3.1'}, {label: 'User 3.2'}]
},
{
label: 'User 4',
items: [{label: 'User 4.1'}, {label: 'User 4.2'}]
}
],
[
{
label: 'User 5',
items: [{label: 'User 5.1'}, {label: 'User 5.2'}]
},
{
label: 'User 6',
items: [{label: 'User 6.1'}, {label: 'User 6.2'}]
}
]
]
},
{
label: 'Events', icon: 'pi pi-fw pi-calendar',
items: [
[
{
label: 'Event 1',
items: [{label: 'Event 1.1'}, {label: 'Event 1.2'}]
},
{
label: 'Event 2',
items: [{label: 'Event 2.1'}, {label: 'Event 2.2'}]
}
],
[
{
label: 'Event 3',
items: [{label: 'Event 3.1'}, {label: 'Event 3.2'}]
},
{
label: 'Event 4',
items: [{label: 'Event 4.1'}, {label: 'Event 4.2'}]
}
]
]
},
{
label: 'Settings', icon: 'pi pi-fw pi-cog',
items: [
[
{
label: 'Setting 1',
items: [{label: 'Setting 1.1'}, {label: 'Setting 1.2'}]
},
{
label: 'Setting 2',
items: [{label: 'Setting 2.1'}, {label: 'Setting 2.2'}]
},
{
label: 'Setting 3',
items: [{label: 'Setting 3.1'}, {label: 'Setting 3.2'}]
}
],
[
{
label: 'Setting 4',
items: [{label: 'Setting 4.1'}, {label: 'Setting 4.2'}]
}
]
]
}
]
}
}
}
Default orientation is "horizontal" with "vertical" as the alternative.
<MegaMenu :model="items" orientation="vertical" />
Two slots named "start" and "end" are provided to embed content before or after the items. In additon MegaMenu, offers item customization with the item template that receives the menuitem instance from the model as a parameter.
<MegaMenu :model="items">
<template #start>
Before
</template>
<template #item="{item}">
<a :href="item.url">{{item.label}}</a>
</template>
<template #end>
After
</template>
</MegaMenu>
router-link with route configuration can also be used within templating for further customization.
<MegaMenu :model="items">
<template #item="{item}">
<router-link :to="item.to" custom v-slot="{href, route, navigate, isActive, isExactActive}">
<a :href="href" @click="navigate" :class="{'active-link': isActive, 'active-link-exact': isExactActive}">{{route.fullPath}}</a>
</router-link>
</template>
</MegaMenu>
Any property as style and class are passed to the main container element. Following are the additional properties to configure the component.
Name | Type | Default | Description |
---|---|---|---|
model | array | null | An array of menuitems. |
orientation | string | horizontal | Defines the orientation, valid values are horizontal and vertical. |
exact | boolean | true | Whether to apply 'router-link-active-exact' class if route exactly matches the item path. |
disabled | boolean | false | When present, it specifies that the component should be disabled. |
tabindex | number | 0 | Index of the element in tabbing order. |
aria-label | string | null | Defines a string value that labels an interactive element. |
aria-labelledby | string | null | Establishes relationships between the component and label(s) where its value should be one or more element IDs. |
Name | Parameters | Description |
---|---|---|
focus | event | Callback to invoke when the component receives focus. |
blur | event | Callback to invoke when the component loses focus. |
Name | Parameters |
---|---|
item | item: Menuitem instance |
start | - |
end | - |
Following is the list of structural style classes, for theming classes visit
Name | Element |
---|---|
p-megamenu | Container element. |
p-megamenu-horizontal | Container element in horizontal orientation. |
p-megamenu-vertical | Container element in vertical orientation. |
p-megamenu-root-list | Root list element. |
p-megamenu-panel | Submenu container. |
p-megamenu-submenu | Submenu list element. |
p-submenu-list | 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. |
p-submenu-icon | Arrow icon of a submenu. |
MegaMenu component uses the menubar role along with aria-orientation and the value to describe the component 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 MegaMenu uses the menu role with an aria-labelledby defined as the id of the submenu root menuitem label. In addition, root 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 | 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 | 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 | If focus is inside a popup submenu, closes the submenu and moves focus to the root item of the closed submenu. |
down arrow | If focus is on a root element, open a submenu and moves focus to the first element in the submenu otherwise moves focus to the next menuitem within the submenu. |
up arrow | If focus is on a root element, opens a submenu and moves focus to the last element in the submenu otherwise moves focus to the previous menuitem within the submenu. |
alt + up arrow | If focus is inside a popup menu, moves focus to the first element in the submenu otherwise closes the submenu and moves focus to the root item of the closed submenu in horizontal mode. |
right arrow | If focus is on a root element, moves focus to the next menuitem. If the focus in inside a submenu, moves focus to the first menuitem of the next menu group. |
left arrow | If focus is on a root element, moves focus to the previous menuitem. If the focus in inside a submenu, moves focus to the first menuitem of the previous menu group. |
home | Moves focus to the first menuitem within the submenu. |
end | Moves focus to the last menuitem within the submenu. |
any printable character | Moves focus to the menuitem whose label starts with the characters being typed. |
None.