import {MenubarModule} from 'primeng/menubar';
import {MenuItem} from 'primeng/api';
Menubar uses the common menumodel api to define its items, visit MenuModel API for details.
Menubar requires nested menuitems as its model.
<p-menubar [model]="items"></p-menubar>
export class MenubarDemo {
items: MenuItem[];
ngOnInit() {
this.items = [
{
label: 'File',
items: [{
label: 'New',
icon: 'fa-plus',
items: [
{label: 'Project'},
{label: 'Other'},
]
},
{label: 'Open'},
{label: 'Quit'}
]
},
{
label: 'Edit',
icon: 'fa-edit',
items: [
{label: 'Undo', icon: 'fa-mail-forward'},
{label: 'Redo', icon: 'fa-mail-reply'}
]
}
];
}
}
Custom content can be placed between p-menubar tags.
<p-menubar [model]="items">
<input type="text" pInputText placeholder="Search">
<button pButton label="Logout" icon="fa-sign-out"></button>
</p-menubar>
| Name | Type | Default | Description |
|---|---|---|---|
| model | array | null | An array of menuitems. |
| autoDisplay | boolean | true | Display menu item when mouse enter or display menu item when clicked |
| style | string | null | Inline style of the component. |
| styleClass | string | null | Style class of the component. |
| baseZIndex | number | 0 | Base zIndex value to use in layering. |
| autoZIndex | boolean | true | Whether to automatically manage layering. |
Following is the list of structural style classes, for theming classes visit theming page.
| Name | Element |
|---|---|
| ui-menubar | Container element. |
| ui-menu-list | List element. |
| ui-menuitem | Menuitem element. |
| ui-menuitem-text | Label of a menuitem. |
| ui-menuitem-icon | Icon of a menuitem. |
| ui-submenu-icon | Arrow icon of a submenu. |
None.
<p-menubar [model]="items">
<div>
<input type="text" pInputText placeholder="Search">
<button pButton label="Logout" icon="fa-sign-out"></button>
</div>
</p-menubar>
<p-menubar [model]="items" [autoDisplay]="false">
<div>
<input type="text" pInputText placeholder="Search">
<button pButton label="Logout" icon="fa-sign-out"></button>
</div>
</p-menubar>
export class MenubarDemo {
items: MenuItem[];
ngOnInit() {
this.items = [
{
label: 'File',
icon: 'fa-file-o',
items: [{
label: 'New',
icon: 'fa-plus',
items: [
{label: 'Project'},
{label: 'Other'},
]
},
{label: 'Open'},
{separator: true},
{label: 'Quit'}
]
},
{
label: 'Edit',
icon: 'fa-edit',
items: [
{label: 'Undo', icon: 'fa-mail-forward'},
{label: 'Redo', icon: 'fa-mail-reply'}
]
},
{
label: 'Help',
icon: 'fa-question',
items: [
{
label: 'Contents'
},
{
label: 'Search',
icon: 'fa-search',
items: [
{
label: 'Text',
items: [
{
label: 'Workspace'
}
]
},
{
label: 'File'
}
]}
]
},
{
label: 'Actions',
icon: 'fa-gear',
items: [
{
label: 'Edit',
icon: 'fa-refresh',
items: [
{label: 'Save', icon: 'fa-save'},
{label: 'Update', icon: 'fa-save'},
]
},
{
label: 'Other',
icon: 'fa-phone',
items: [
{label: 'Delete', icon: 'fa-minus'}
]
}
]
},
{
label: 'Quit', icon: 'fa-minus'
}
];
}
}