Menubar is a horizontal menu component.
import { MenubarModule } from 'primeng/menubar';
Menubar requires nested menuitems as its model.
<p-menubar [model]="items" />
Custom content can be placed inside the menubar using the start and end templates.
<p-menubar [model]="items">
<ng-template pTemplate="start">
<svg width="33" height="35" viewBox="0 0 33 35" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="..." fill="var(--primary-color)" />
<mask id="mask0_1_36" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="31" height="33">
<path d="..." fill="var(--primary-color-text)" />
</mask>
<g mask="url(#mask0_1_36)">
<path fill-rule="evenodd" clip-rule="evenodd" d="..." />
</g>
<path d="..." fill="var(--primary-color-text)" />
<path d="..." fill="var(--primary-color-text)" />
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="..."
fill="var(--primary-color-text)"
/>
<path d="..." fill="var(--primary-color-text)" />
<path d="..." fill="var(--primary-color-text)" />
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="..."
fill="var(--primary-color-text)"
/>
<path d="..." fill="var(--primary-color-text)" />
<path d="..." fill="var(--primary-color-text)" />
<path d="..." fill="var(--primary-color-text)" />
<path d="..." fill="var(--primary-color-text)" />
</svg>
</ng-template>
<ng-template pTemplate="item" let-item let-root="root">
<a pRipple class="flex align-items-center p-menuitem-link">
<span [class]="item.icon"></span>
<span class="ml-2">{{ item.label }}</span>
<p-badge *ngIf="item.badge" [ngClass]="{ 'ml-auto': !root, 'ml-2': root }" [value]="item.badge" />
<span *ngIf="item.shortcut" class="ml-auto border-1 surface-border border-round surface-100 text-xs p-1">{{ item.shortcut }}</span>
<i *ngIf="item.items" [ngClass]="['pi', root ? 'pi-angle-down ml-2' : 'pi-angle-right ml-auto']"></i>
</a>
</ng-template>
<ng-template pTemplate="end">
<div class="flex align-items-center gap-2">
<input type="text" pInputText placeholder="Search" class="w-8rem sm:w-auto" />
<p-avatar image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png" shape="circle" />
</div>
</ng-template>
</p-menubar>
The command property defines the callback to run when an item is activated by click or a key event.
<p-toast />
<p-menubar [model]="items" />
Items with navigation are defined with templating to be able to use a routerLink directive, an external link or programmatic navigation.
<p-menubar [model]="items">
<ng-template pTemplate="item" let-item>
<ng-container *ngIf="item.route; else urlRef">
<a [routerLink]="item.route" class="p-menuitem-link">
<span [class]="item.icon"></span>
<span class="ml-2">{{ item.label }}</span>
</a>
</ng-container>
<ng-template #urlRef>
<a *ngIf="item.url; else noLink" [href]="item.url" class="p-menuitem-link">
<span [class]="item.icon"></span>
<span class="ml-2">{{ item.label }}</span>
</a>
</ng-template>
<ng-template #noLink>
<div class="p-menuitem-link">
<span [class]="item.icon"></span>
<span class="ml-2">{{ item.label }}</span>
<span class="pi pi-fw pi-angle-down ml-2"></span>
</div>
</ng-template>
</ng-template>
</p-menubar>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-menubar | Container element. |
p-menu-list | List element. |
p-menuitem | Menuitem element. |
p-menuitem-text | Label of a menuitem. |
p-menuitem-icon | Icon of a menuitem. |
p-submenu-icon | Arrow icon of a submenu. |
Menubar component uses the menubar 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 MenuBar uses the menu role with an aria-labelledby defined as the id of the submenu root menuitem label. In addition, menuitems that open a submenu have aria-haspopup, aria-expanded and aria-controls to define the relation between the item and the submenu.
In mobile viewports, a menu icon appears with a button role along with aria-haspopup, aria-expanded and aria-controls to manage the relation between the overlay menubar and the button. The value to describe the button can be defined aria-label or aria-labelledby specified using buttonProps, by default navigation key of the aria property from the locale API as the aria-label.
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 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. |
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. |
right arrow | If focus is on a root element, moves focus to the next menuitem otherwise opens a submenu if there is one available and moves focus to the first item. |
left arrow | If focus is on a root element, moves focus to the previous menuitem otherwise closes a submenu and moves focus to the root item of the closed submenu. |
home | Moves focus to the first menuitem within the submenu. |
end | Moves focus to the last menuitem within the submenu. |
API defines helper props, events and others for the PrimeNG Menubar module.
Menubar is a horizontal menu component.
Defines the input properties of the component.
name | type | default | description | ||
---|---|---|---|---|---|
MenuItem[] | |||||
Object | |||||
string | |||||
boolean | |||||
number | |||||
boolean | |||||
boolean | |||||
number | |||||
string | |||||
string | |||||
string |
Defines emit that determine the behavior of the component based on a given condition or report the actions that the component takes.
name | parameters | description | |
---|---|---|---|
event : FocusEvent | |||
event : FocusEvent |
Defines the templates used by the component.
name | parameters | description | |
---|---|---|---|
context : {
$implicit: MenuItem, // Item instance.
root: boolean, // Whether root or not
} | |||
Defines the custom interfaces used by the module.
MenuItem provides the following properties. Note that not all of them may be utilized by the tabmenu component.
name | type | description |
---|---|---|
string | ||
string | ||
- | ||
string | ||
MenuItem[] | ||
boolean | ||
boolean | ||
boolean | ||
string | ||
boolean | ||
any | ||
boolean | ||
string | ||
string | ||
string | ||
string | ||
Object | ||
string | ||
string | ||
string | ||
any | ||
string | ||
any | ||
Object | ||
string | ||
QueryParamsHandling | ||
boolean | ||
boolean | ||
boolean | ||
Object | ||
string | ||
Object | ||
TooltipOptions |