TabMenu is a navigation component that displays items as tab headers. Example below uses nested routes with TabMenu.
import { TabMenuModule } from 'primeng/tabmenu';
TabMenu requires a collection of menuitems as its model.
<p-tabMenu [model]="items" />
For controlled mode, use activeItem property along with activeItemChange event are needed to manage the active item.
<div class="flex mb-2 gap-2 justify-content-end">
<p-button
(onClick)="activeItem = items[0]"
[rounded]="true"
label="1"
styleClass="w-2rem h-2rem p-0"
[outlined]="activeItem !== items[0]" />
<p-button
(onClick)="activeItem = items[1]"
[rounded]="true"
label="2"
styleClass="w-2rem h-2rem p-0"
[outlined]="activeItem !== items[1]" />
<p-button
(onClick)="activeItem = items[2]"
[rounded]="true"
label="3"
styleClass="w-2rem h-2rem p-0"
[outlined]="activeItem !== items[2]" />
</div>
<p-tabMenu
[model]="items"
[activeItem]="activeItem"
(activeItemChange)="onActiveItemChange($event)" />
TabMenu supports templating via the item template which gets the menuitem instance and the index.
<p-tabMenu [model]="items" [activeItem]="activeItem">
<ng-template pTemplate="item" let-item>
<a pRipple class="flex align-items-center gap-2 p-menuitem-link">
<img
[alt]="item.name"
[src]="'https://primefaces.org/cdn/primeng/images/demo/avatar/' + item.image"
style="width: 32px" />
<span class="font-bold">
{{ item.name }}
</span>
</a>
</ng-template>
</p-tabMenu>
The command property defines the callback to run when an item is activated by click or a key event.
<p-toast />
<p-tabMenu [model]="items" />
Items with navigation are defined with templating to be able to use a router link directive, an external link or programmatic navigation.
<p-tabMenu [model]="items">
<ng-template pTemplate="item" let-item>
<ng-container *ngIf="item.route; else elseBlock">
<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 #elseBlock>
<a [href]="item.url" class="p-menuitem-link">
<span [class]="item.icon"></span>
<span class="ml-2">
{{ item.label }}
</span>
</a>
</ng-template>
</ng-template>
</p-tabMenu>
Following is the list of structural style classes, for theming classes visit theming page.
| Name | Element |
|---|---|
| p-tabmenu | Container element. |
| p-tabmenu-nav | List element of headers. |
| p-tabmenuitem | Menuitem element. |
| p-menuitem-link | Link inside a menuitem. |
| p-menuitem-text | Label of a menuitem. |
| p-menuitem-icon | Icon of a menuitem. |
TabMenu 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.
| Key | Function |
|---|---|
| tab | Adds focus to the active tab header when focus moves in to the component, if there is already a focused tab header moves the focus out of the component based on the page tab sequence. |
| enter | Activates the focused tab header. |
| space | Activates the focused tab header. |
| right arrow | Moves focus to the next header. |
| left arrow | Moves focus to the previous header. |
| home | Moves focus to the first header. |
| end | Moves focus to the last header. |
API defines helper props, events and others for the PrimeNG TabMenu module.
TabMenu is a navigation component that displays items as tab headers.
Defines the input properties of the component.
| name | type | default | description | ||
|---|---|---|---|---|---|
| MenuItem[] | |||||
| MenuItem | |||||
| boolean | |||||
| Object | |||||
| 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 | |
|---|---|---|---|
value : MenuItem |
Defines the templates used by the component.
| name | parameters | description | |
|---|---|---|---|
context : {
$implicit: any, // Item instance.
index: number, // Item index.
} | |||
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 |