Tiered MenuTieredMenu displays submenus in nested overlays.

TieredMenu - 图1

Documentation

Import

  1. import {TieredMenuModule} from 'primeng/tieredmenu';
  2. import {MenuItem} from 'primeng/api';
  3.  

MenuModel API

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

Getting Started

TieredMenu requires nested menuitems as its model.

  1. <p-tieredMenu [model]="items"></p-tieredMenu>
  2.  
  1. export class TieredMenuDemo {
  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.  

Popup Mode

Menu is inline by default, popup mode is also supported by enabling popup property and calling toggle method by passing the event from the anchor element.

  1. <p-tieredMenu #menu [model]="items" [popup]="true"></p-tieredMenu>
  2. <button #btn type="button" pButton icon="fa fa fa-fw fa-list" label="Show" (click)="menu.toggle($event)"></button>
  3.  

Animation Configuration

Transition of the open and hide animations can be customized using the showTransitionOptions and hideTransitionOptions properties, example below disables the animations altogether.

  1. <p-tieredMenu [showTransitionOptions]="'0ms'" [hideTransitionOptions]="'0ms'" #menu [model]="items" [popup]="true"></p-tieredMenu>
  2. <button #btn type="button" pButton icon="fa fa fa-fw fa-list" label="Show" (click)="menu.toggle($event)"></button>
  3.  

Properties

NameTypeDefaultDescription
modelarraynullAn array of menuitems.
popupbooleanfalseDefines if menu would displayed as a popup.
appendToanynullTarget element to attach the overlay, valid values are "body" or a local ng-template variable of another element.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.
hideDelaynumber250Delay in milliseconds to hide the menu on mouse leave.
showTransitionOptionsstring225ms ease-outTransition options of the show animation.
hideTransitionOptionsstring195ms ease-inTransition options of the hide animation.

Methods

NameParametersDescription
toggleevent: browser eventToggles the visibility of the popup menu.
showevent: browser eventDisplays the popup menu.
hide-Hides the popup menu.

Styling

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

NameElement
ui-tieredmenuContainer 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. <h3 class="first">Default</h3>
  2. <p-tieredMenu [model]="items"></p-tieredMenu>
  3. <h3>Popup</h3>
  4. <p-tieredMenu #menu [model]="items" [popup]="true"></p-tieredMenu>
  5. <button #btn type="button" pButton icon="pi pi-bars" label="Show" (click)="menu.toggle($event)"></button>
  6.  
  1. export class TieredMenuDemo {
  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.