Sidebar is a panel component displayed as an overlay at the edges of the screen.
import { SidebarModule } from 'primeng/sidebar';
Sidebar is used as a container and visibility is controlled with a binding to visible.
<p-sidebar [(visible)]="sidebarVisible">
<h3>Sidebar</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</p-sidebar>
<p-button (click)="sidebarVisible = true" icon="pi pi-arrow-right"></p-button>
Sidebar location is configured with the position property that can take left, right, top and bottom as a value.
<p-sidebar [(visible)]="sidebarVisible1" position="left">
<h3>Left Sidebar</h3>
</p-sidebar>
<p-sidebar [(visible)]="sidebarVisible2" position="right">
<h3>Right Sidebar</h3>
</p-sidebar>
<p-sidebar [(visible)]="sidebarVisible3" position="top">
<h3>Top Sidebar</h3>
</p-sidebar>
<p-sidebar [(visible)]="sidebarVisible4" position="bottom">
<h3>Bottom Sidebar</h3>
</p-sidebar>
<p-button type="button" class="mr-2" (click)="sidebarVisible1 = true" icon="pi pi-arrow-right"></p-button>
<p-button type="button" class="mr-2" (click)="sidebarVisible2 = true" icon="pi pi-arrow-left"></p-button>
<p-button type="button" class="mr-2" (click)="sidebarVisible3 = true" icon="pi pi-arrow-down"></p-button>
<p-button type="button" class="mr-2" (click)="sidebarVisible4 = true" icon="pi pi-arrow-up"></p-button>
Sidebar can cover the whole page when fullScreen property is enabled.
<p-sidebar [(visible)]="sidebarVisible" [fullScreen]="true">
<h3>Full Screen Sidebar</h3>
</p-sidebar>
<p-button (click)="sidebarVisible = true" icon="pi pi-th-large"></p-button>
Sidebar dimension can be defined with style or styleClass properties which can also be responsive when used with a CSS utility library like PrimeFlex.
<p-sidebar [(visible)]="sidebarVisible" styleClass="w-30rem">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</p-sidebar>
<p-button (click)="sidebarVisible = true" icon="pi pi-arrow-right"></p-button>
Sidebar is customizable by header, content, footer templates.
<p-sidebar [(visible)]="sidebarVisible">
<ng-template pTemplate="header">Header Content</ng-template>
<ng-template pTemplate="content">Body Content</ng-template>
<ng-template pTemplate="footer">Footer Content</ng-template>
</p-sidebar>
<p-button (click)="sidebarVisible = true" icon="pi pi-arrow-right"></p-button>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-sidebar | Container element |
p-sidebar-left | Container element of left sidebar. |
p-sidebar-right | Container element of right sidebar. |
p-sidebar-top | Container element of top sidebar. |
p-sidebar-bottom | Container element of bottom sidebar. |
p-sidebar-full | Container element of a full screen sidebar. |
p-sidebar-active | Container element when sidebar is visible. |
p-sidebar-close | Close anchor element. |
p-sidebar-sm | Small sized sidebar. |
p-sidebar-md | Medium sized sidebar. |
p-sidebar-lg | Large sized sidebar. |
p-sidebar-mask | Modal layer of the sidebar. |
Sidebar component uses complementary role by default, since any attribute is passed to the root element aria role can be changed depending on your use case and additional attributes like aria-labelledby can be added. In addition aria-modal is added since focus is kept within the sidebar when opened.
It is recommended to use a trigger component that can be accessed with keyboard such as a button, if not adding tabIndex would be necessary.
Trigger element also requires aria-expanded and aria-controls to be handled explicitly.
<p-button
icon="pi pi-arrow-right"
(click)="sidebarVisible = true"
aria-controls="{{sidebarVisible ? 'sidebar' : null}}"
aria-expanded="{{sidebarVisible ? true : false}}"
></p-button>
<p-sidebar
[(visible)]="sidebarVisible"
id="sidebar"
(onHide)="sidebarVisible = false"
role="region"
>
content
</p-sidebar>
Key | Function |
---|---|
tab | Moves focus to the next the focusable element within the sidebar. |
shift + tab | Moves focus to the previous the focusable element within the sidebar. |
escape | Closes the dialog if closeOnEscape is true. |
Key | Function |
---|---|
enter | Closes the sidebar. |
space | Closes the sidebar. |
API defines helper props, events and others for the PrimeNG Sidebar module.
Name | Type | Default | Description |
---|---|---|---|
visible | boolean | false | Specifies the visibility of the dialog. |
position | string | left | Specifies the position of the sidebar, valid values are "left", "right", "bottom" and "top". |
fullScreen | boolean | false | Adds a close icon to the header to hide the dialog. |
appendTo | any | null | Target element to attach the dialog, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name). |
style | string | null | Inline style of the component. |
styleClass | string | null | Style class of the component. |
blockScroll | boolean | false | Whether to block scrolling of the document when sidebar is active. |
baseZIndex | number | 0 | Base zIndex value to use in layering. |
autoZIndex | boolean | true | Whether to automatically manage layering. |
modal | boolean | true | Whether an overlay mask is displayed behind the sidebar. |
dismissible | boolean | true | Whether to dismiss sidebar on click of the mask. |
showCloseIcon | boolean | true | Whether to display the close icon. |
transitionOptions | string | 150ms cubic-bezier(0, 0, 0.2, 1) | Transition options of the animation. |
ariaCloseLabel | string | close | Aria label of the close icon. |
closeOnEscape | boolean | true | Specifies if pressing escape key should hide the sidebar. |
Name | Parameters | Description |
---|---|---|
onShow | event: Event object | Callback to invoke when dialog is shown. |
onHide | event: Event object | Callback to invoke when dialog is hidden. |
visibleChange | event: Event object | Callback to invoke when dialog visibility is changed. |
Name | Parameters |
---|---|
header | - |
content | - |
footer | - |
closeicon | - |