Menu

Menu is a navigation/command component that supports dynamic and static positioning.


import { Menu } from 'primereact/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.


<Toast ref={toast} />
<Menu model={items} />
 

Popup mode is enabled by adding popup property and calling toggle method with an event of the target.


<Toast ref={toast}></Toast>
<Menu model={items} popup ref={menu} />
<Button label="Show" icon="pi pi-bars" onClick={(e) => menu.current.toggle(e)} />
 

Custom content can be placed inside the menuitem using the template property.


<Menu model={items} />
 

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

NameElement
p-menuContainer element.
p-menu-listList element.
p-menuitemMenuitem element.
p-menuitem-textLabel of a menuitem.
p-menuitem-iconIcon of a menuitem.
Accessibility guide documents the specification of this component based on WCAG guidelines, the implementation is in progress.

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 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 Menu uses the group role with an aria-labelledby defined as the id of the submenu root menuitem label.

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 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.
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.
homeMoves focus to the first menuitem.
endMoves focus to the last menuitem.
Visit the API documentation for detailed information about all the properties, events and methods of the component.