Slide MenuSlideMenu displays submenus with slide animation.

SlideMenu - 图1

Documentation

Import

  1. import {SlideMenuModule} from 'primeng/slidemenu';
  2. import {MenuItem} from 'primeng/api';
  3.  

MenuModel API

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

Getting Started

SlideMenu requires nested menuitems as its model.

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

SlideMenu 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-slideMenu #menu [model]="items" [popup]="true"></p-slideMenu>
  2. <button #btn type="button" pButton icon="fa fa-list" label="Show" (click)="menu.toggle($event)"></button>
  3.  

Effects

The easing function to use is "ease-out" by default and this can be customized using easing property. See here for possible alternative values.

  1. <p-slideMenu #menu [model]="items" effectDuration="1000" easing="ease-in"></p-slideMenu>
  2.  

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

Properties

NameTypeDefaultDescription
modelarraynullAn array of menuitems.
popupbooleanfalseDefines if menu would displayed as a popup.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
easingstringease-outEasing animation to use for sliding.
effectDurationany250Duration of the sliding animation in milliseconds.
backLabelstringBackLabel of element to navigate back.
menuWidthnumber180Width of the submenus.
viewportHeightnumber175Height of the scrollable area, a scrollbar appears if a menu height is longer than this value.
appendToanynullTarget element to attach the overlay, valid values are "body" or a local ng-template variable of another element.
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.
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-slidemenuContainer element.
ui-slidemenu-wrapperWrapper of content.
ui-slidemenu-contentContent element.
ui-slidemenu-backwardElement to navigate to previous menu on click.
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-slideMenu [model]="items" [viewportHeight]="250"></p-slideMenu>
  3. <h3>Popup</h3>
  4. <p-slideMenu #menu [model]="items" [popup]="true" [viewportHeight]="250"></p-slideMenu>
  5. <button #btn type="button" pButton icon="pi pi-bars" label="Show" (click)="menu.toggle($event)"></button>
  6.  
  1. export class SlideMenuDemo {
  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.