MegaMenu

MegaMenu is navigation component that displays submenus together.


import { MegaMenuModule } from 'primeng/megamenu';

MegaMenu requires a collection of menuitems as its model.


<p-megaMenu [model]="items"></p-megaMenu>

Layout of the MegaMenu is changed with the orientation property that accepts horizontal and vertical as options.


<p-megaMenu [model]="items"></p-megaMenu>

Custom content can be placed between p-megaMenu tags. Megamenu should be horizontal for custom content.


<p-megaMenu [model]="items" styleClass="flex">
    <ng-template pTemplate="start">
        <img src="https://primefaces.org/cdn/primeng/images/primeng.svg" height="40" class="mr-2" />
    </ng-template>
    <ng-template pTemplate="end">
        <input type="text" pInputText placeholder="Search" />
    </ng-template>
</p-megaMenu>

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-megamenuContainer element.
p-menu-listList element.
p-menuitemMenuitem element.
p-menuitem-textLabel of a menuitem.
p-menuitem-iconIcon of a menuitem.
p-submenu-iconArrow icon of a submenu.

Screen Reader

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.

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 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.
enterIf menuitem has a submenu, toggles the visibility of the submenu otherwise activates the menuitem and closes all open overlays.
spaceIf menuitem has a submenu, toggles the visibility of the submenu otherwise activates the menuitem and closes all open overlays.
escapeIf focus is inside a popup submenu, closes the submenu and moves focus to the root item of the closed submenu.
down arrowIf 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 arrowIf 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.
right arrowIf 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 arrowIf 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.
homeMoves focus to the first menuitem within the submenu.
endMoves focus to the last menuitem within the submenu.