SidebarSidebar is a panel component displayed as an overlay.

Sidebar - 图1

Documentation

Import

  1. import {SidebarModule} from 'primeng/sidebar';
  2.  

Getting Started

Sidebar is used as a container and visibility is controlled with visible property.

  1. <p-sidebar [(visible)]="display">
  2. Content
  3. </p-sidebar>
  4. <button type="text" (click)="display = true" pButton icon="pi pi-plus" label="Show"></button>
  5.  

Position

Sidebar can either be located as the left (default), right, top or bottom of the screen depending on the position property.

  1. <p-sidebar [(visible)]="display" position="right">
  2. Content
  3. </p-sidebar>
  4.  

Size

Sidebar size can be changed using a fixed value or using one of the three predefined ones.

  1. <p-sidebar [(visible)]="display" [style]="{width:'30em'}"></p-sidebar>
  2. <p-sidebar [(visible)]="display" styleClass="ui-sidebar-sm"></p-sidebar>
  3. <p-sidebar [(visible)]="display" styleClass="ui-sidebar-md"></p-sidebar>
  4. <p-sidebar [(visible)]="display" styleClass="ui-sidebar-lg"></p-sidebar>
  5.  

Full Screen

Full screen mode allows the sidebar to cover whole screen.

  1. <p-sidebar [(visible)]="display" [fullScreen]="true">
  2. Content
  3. </p-sidebar>
  4.  

Properties

NameTypeDefaultDescription
visiblebooleanfalseSpecifies the visibility of the dialog.
positionstringleftSpecifies the position of the sidebar, valid values are "left", "right", "bottom" and "top".
fullScreenbooleanfalseAdds a close icon to the header to hide the dialog.
appendToanynullTarget element to attach the dialog, valid values are "body" or a local ng-template variable of another element.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
blockScrollbooleanfalseWhether to block scrolling of the document when sidebar is active.
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.
modalbooleantrueWhether an overlay mask is displayed behind the sidebar.
dismissiblebooleantrueWhether to dismiss sidebar on click of the mask.
showCloseIconbooleantrueWhether to display the close icon.

Events

NameParametersDescription
onShowevent: Event objectCallback to invoke when dialog is shown.
onHideevent: Event objectCallback to invoke when dialog is hidden.

Styling

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

NameElement
ui-sidebarContainer element
ui-sidebar-leftContainer element of left sidebar.
ui-sidebar-rightContainer element of right sidebar.
ui-sidebar-topContainer element of top sidebar.
ui-sidebar-bottomContainer element of bottom sidebar.
ui-sidebar-fullContainer element of a full screen sidebar.
ui-sidebar-activeContainer element when sidebar is visible.
ui-sidebar-closeClose anchor element.
ui-sidebar-smSmall sized sidebar.
ui-sidebar-mdMedium sized sidebar.
ui-sidebar-lgLarge sized sidebar.
ui-sidebar-maskModal layer of the sidebar.

Dependencies

None.

Source

View on GitHub

  1. <p-sidebar [(visible)]="visibleSidebar1" [baseZIndex]="10000">
  2. <h1 style="font-weight:normal">Left Sidebar</h1>
  3. <button pButton type="button" (click)="visibleSidebar1 = false" label="Save" class="ui-button-success"></button>
  4. <button pButton type="button" (click)="visibleSidebar1 = false" label="Cancel" class="ui-button-secondary"></button>
  5. </p-sidebar>
  6. <p-sidebar [(visible)]="visibleSidebar2" position="right" [baseZIndex]="10000">
  7. <h1 style="font-weight:normal">Right Sidebar</h1>
  8. <button pButton type="button" (click)="visibleSidebar2 = false" label="Save" class="ui-button-success"></button>
  9. <button pButton type="button" (click)="visibleSidebar2 = false" label="Cancel" class="ui-button-secondary"></button>
  10. </p-sidebar>
  11. <p-sidebar [(visible)]="visibleSidebar3" position="top" [baseZIndex]="10000">
  12. <h1 style="font-weight:normal">Top Sidebar</h1>
  13. <button pButton type="button" (click)="visibleSidebar3 = false" label="Save" class="ui-button-success"></button>
  14. <button pButton type="button" (click)="visibleSidebar3 = false" label="Cancel" class="ui-button-secondary"></button>
  15. </p-sidebar>
  16. <p-sidebar [(visible)]="visibleSidebar4" position="bottom" [baseZIndex]="10000">
  17. <h1 style="font-weight:normal">Bottom Sidebar</h1>
  18. <button pButton type="button" (click)="visibleSidebar4 = false" label="Save" class="ui-button-success"></button>
  19. <button pButton type="button" (click)="visibleSidebar4 = false" label="Cancel" class="ui-button-secondary"></button>
  20. </p-sidebar>
  21. <p-sidebar [(visible)]="visibleSidebar5" [fullScreen]="true" [baseZIndex]="10000">
  22. <h1 style="font-weight:normal">Full Screen Sidebar</h1>
  23. <button pButton type="button" (click)="visibleSidebar5 = false" label="Save" class="ui-button-success"></button>
  24. <button pButton type="button" (click)="visibleSidebar5 = false" label="Cancel" class="ui-button-secondary"></button>
  25. </p-sidebar>
  26. <button pButton type="button" (click)="visibleSidebar1 = true" icon="pi pi-arrow-right"></button>
  27. <button pButton type="button" (click)="visibleSidebar2 = true" icon="pi pi-arrow-left"></button>
  28. <button pButton type="button" (click)="visibleSidebar3 = true" icon="pi pi-arrow-down"></button>
  29. <button pButton type="button" (click)="visibleSidebar4 = true" icon="pi pi-arrow-up"></button>
  30. <button pButton type="button" (click)="visibleSidebar5 = true" icon="pi pi-th-large"></button>
  31.  
  1. export class SidebarDemo {
  2. visibleSidebar1;
  3. visibleSidebar2;
  4. visibleSidebar3;
  5. visibleSidebar4;
  6. visibleSidebar5;
  7. }
  8.