MenubarMenubar is an horizontal menu components with support for nested submenus.

Menubar - 图1

Documentation

Import

  1. import {MenubarModule} from 'primeng/menubar';
  2. import {MenuItem} from 'primeng/api';
  3.  

MenuModel API

Menubar uses the common menumodel api to define its items, visit MenuModel API for details.

Getting Started

Menubar requires nested menuitems as its model.

  1. <p-menubar [model]="items"></p-menubar>
  2.  
  1. export class MenubarDemo {
  2. items: MenuItem[];
  3. ngOnInit() {
  4. this.items = [
  5. {
  6. label: 'File',
  7. items: [{
  8. label: 'New',
  9. icon: 'pi pi-fw pi-plus',
  10. items: [
  11. {label: 'Project'},
  12. {label: 'Other'},
  13. ]
  14. },
  15. {label: 'Open'},
  16. {label: 'Quit'}
  17. ]
  18. },
  19. {
  20. label: 'Edit',
  21. icon: 'pi pi-fw pi-pencil',
  22. items: [
  23. {label: 'Delete', icon: 'pi pi-fw pi-trash'},
  24. {label: 'Refresh', icon: 'pi pi-fw pi-refresh'}
  25. ]
  26. }
  27. ];
  28. }
  29. }
  30.  

Custom Content

Custom content can be placed between p-menubar tags.

  1. <p-menubar [model]="items">
  2. <input type="text" pInputText placeholder="Search">
  3. <button pButton label="Logout" icon="fa fa-sign-out"></button>
  4. </p-menubar>
  5.  

Properties

NameTypeDefaultDescription
modelarraynullAn array of menuitems.
autoDisplaybooleantrueDisplay menu item when mouse enter or display menu item when clicked
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.

Styling

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

NameElement
ui-menubarContainer element.
ui-menu-listList element.
ui-menuitemMenuitem element.
ui-menuitem-textLabel of a menuitem.
ui-menuitem-iconIcon of a menuitem.
ui-submenu-iconArrow icon of a submenu.

Dependencies

None.

Source

View on GitHub

  1. <p-menubar [model]="items">
  2. <div>
  3. <input type="text" pInputText placeholder="Search">
  4. <button pButton label="Logout" icon="fa fa-sign-out" style="margin-left:.25em"></button>
  5. </div>
  6. </p-menubar>
  7. <p-menubar [model]="items" [autoDisplay]="false">
  8. <div>
  9. <input type="text" pInputText placeholder="Search">
  10. <button pButton label="Logout" icon="fa fa-sign-out" style="margin-left:.25em"></button>
  11. </div>
  12. </p-menubar>
  13.  
  1. export class MenubarDemo {
  2. items: MenuItem[];
  3. ngOnInit() {
  4. this.items = [
  5. {
  6. label: 'File',
  7. icon: 'pi pi-fw pi-file',
  8. items: [{
  9. label: 'New',
  10. icon: 'pi pi-fw pi-plus',
  11. items: [
  12. {label: 'Project'},
  13. {label: 'Other'},
  14. ]
  15. },
  16. {label: 'Open'},
  17. {separator:true},
  18. {label: 'Quit'}
  19. ]
  20. },
  21. {
  22. label: 'Edit',
  23. icon: 'pi pi-fw pi-pencil',
  24. items: [
  25. {label: 'Delete', icon: 'pi pi-fw pi-trash'},
  26. {label: 'Refresh', icon: 'pi pi-fw pi-refresh'}
  27. ]
  28. },
  29. {
  30. label: 'Help',
  31. icon: 'pi pi-fw pi-question',
  32. items: [
  33. {
  34. label: 'Contents'
  35. },
  36. {
  37. label: 'Search',
  38. icon: 'pi pi-fw pi-search',
  39. items: [
  40. {
  41. label: 'Text',
  42. items: [
  43. {
  44. label: 'Workspace'
  45. }
  46. ]
  47. },
  48. {
  49. label: 'File'
  50. }
  51. ]}
  52. ]
  53. },
  54. {
  55. label: 'Actions',
  56. icon: 'pi pi-fw pi-cog',
  57. items: [
  58. {
  59. label: 'Edit',
  60. icon: 'pi pi-fw pi-pencil',
  61. items: [
  62. {label: 'Save', icon: 'pi pi-fw pi-save'},
  63. {label: 'Update', icon: 'pi pi-fw pi-save'},
  64. ]
  65. },
  66. {
  67. label: 'Other',
  68. icon: 'pi pi-fw pi-tags',
  69. items: [
  70. {label: 'Delete', icon: 'pi pi-fw pi-minus'}
  71. ]
  72. }
  73. ]
  74. },
  75. {separator:true},
  76. {
  77. label: 'Quit', icon: 'pi pi-fw pi-times'
  78. }
  79. ];
  80. }
  81. }
  82.