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...
</p>
</p-sidebar>
<p-button (onClick)="sidebarVisible = true" icon="pi pi-arrow-right" />
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"
(onClick)="sidebarVisible1 = true"
icon="pi pi-arrow-right" />
<p-button
type="button"
class="mr-2"
(onClick)="sidebarVisible2 = true"
icon="pi pi-arrow-left" />
<p-button
type="button"
class="mr-2"
(onClick)="sidebarVisible3 = true"
icon="pi pi-arrow-down" />
<p-button
type="button"
class="mr-2"
(onClick)="sidebarVisible4 = true"
icon="pi pi-arrow-up" />
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">
<ng-template pTemplate="header">
<span class="font-semibold text-xl">Sidebar</span>
</ng-template>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit...
</p>
</p-sidebar>
<p-button (onClick)="sidebarVisible = true" icon="pi pi-arrow-right" />
Sidebar can cover the whole page when fullScreen property is enabled.
<p-sidebar [(visible)]="sidebarVisible" [fullScreen]="true">
<ng-template pTemplate="header">
<span class="font-semibold text-xl">
Sidebar
</span>
</ng-template>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit...
</p>
</p-sidebar>
<p-button (onClick)="sidebarVisible = true" icon="pi pi-window-maximize" />
Sidebar is customizable by header, content, footer templates.
<p-sidebar [(visible)]="sidebarVisible">
<ng-template pTemplate="header">
<div class="flex align-items-center gap-2">
<p-avatar
image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png"
shape="circle" />
<span class="font-bold">
Amy Elsner
</span>
</div>
</ng-template>
<p>
Lorem ipsum dolor sit amet...
</p>
</p-sidebar>
<p-button (onClick)="sidebarVisible = true" icon="pi pi-plus" />
Headless mode allows you to customize the entire user interface instead of the default elements.
<p-sidebar #sidebarRef [(visible)]="sidebarVisible">
<ng-template pTemplate="headless">
<div class="flex flex-column h-full">
<div class="flex align-items-center justify-content-between px-4 pt-3 flex-shrink-0">
<span class="inline-flex align-items-center gap-2">
<svg width="33" height="35" viewBox="0 0 33 35" fill="none" xmlns="http://www.w3.org/2000/svg" class="block mx-auto">
<path d="M15.1934 0V0V0L0.0391235 5.38288L2.35052 25.3417L15.1934 32.427V32.427V32.427L28.0364 25.3417L30.3478 5.38288L15.1934 0Z" fill="var(--primary-color)" />
<mask id="mask0_1_36" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="31" height="33">
<path d="M15.1934 0V0V0L0.0391235 5.38288L2.35052 25.3417L15.1934 32.427V32.427V32.427L28.0364 25.3417L30.3478 5.38288L15.1934 0Z" fill="var(--primary-color-text)" />
</mask>
<g mask="url(#mask0_1_36)">
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.1935 0V3.5994V3.58318V20.0075V20.0075V32.427V32.427L28.0364 25.3417L30.3478 5.38288L15.1935 0Z" fill="var(--primary-color)" />
</g>
<path d="M19.6399 15.3776L18.1861 15.0547L19.3169 16.6695V21.6755L23.1938 18.4458V12.9554L21.4169 13.6013L19.6399 15.3776Z" fill="var(--primary-color-text)" />
<path d="M10.5936 15.3776L12.0474 15.0547L10.9166 16.6695V21.6755L7.03966 18.4458V12.9554L8.81661 13.6013L10.5936 15.3776Z" fill="var(--primary-color-text)" />
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M11.3853 16.9726L12.6739 15.0309L13.4793 15.5163H16.7008L17.5061 15.0309L18.7947 16.9726V24.254L17.8283 25.7103L16.7008 26.843H13.4793L12.3518 25.7103L11.3853 24.254V16.9726Z"
fill="var(--primary-color-text)"
/>
<path d="M19.3168 24.7437L21.4168 22.6444V20.5451L19.3168 22.3214V24.7437Z" fill="var(--primary-color-text)" />
<path d="M10.9166 24.7437L8.81662 22.6444V20.5451L10.9166 22.3214V24.7437Z" fill="var(--primary-color-text)" />
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M13.0167 5.68861L11.7244 8.7568L13.8244 14.8932H14.7936V5.68861H13.0167ZM15.4397 5.68861V14.8932H16.5706L18.5091 8.7568L17.2167 5.68861H15.4397Z"
fill="var(--primary-color-text)"
/>
<path d="M13.8244 14.8932L6.87813 12.3094L5.90888 8.27235L11.8859 8.7568L13.9859 14.8932H13.8244Z" fill="var(--primary-color-text)" />
<path d="M16.5706 14.8932L23.5169 12.3094L24.4861 8.27235L18.3476 8.7568L16.4091 14.8932H16.5706Z" fill="var(--primary-color-text)" />
<path d="M18.8321 8.27235L22.2245 7.94938L19.9629 5.68861H17.7013L18.8321 8.27235Z" fill="var(--primary-color-text)" />
<path d="M11.4013 8.27235L8.00893 7.94938L10.2705 5.68861H12.5321L11.4013 8.27235Z" fill="var(--primary-color-text)" />
</svg>
<span class="font-semibold text-2xl text-primary">Your Logo</span>
</span>
<span>
<p-button type="button" (onClick)="closeCallback($event)" icon="pi pi-times" rounded="true" outlined="true" styleClass="h-2rem w-2rem"></p-button>
</span>
</div>
<div class="overflow-y-auto">
<ul class="list-none p-3 m-0">
<li>
<div
pRipple
pStyleClass="@next"
enterClass="hidden"
enterActiveClass="slidedown"
leaveToClass="hidden"
leaveActiveClass="slideup"
class="p-3 flex align-items-center justify-content-between text-600 cursor-pointer p-ripple"
>
<span class="font-medium">FAVORITES</span>
<i class="pi pi-chevron-down"></i>
</div>
<ul class="list-none p-0 m-0 overflow-hidden">
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-home mr-2"></i>
<span class="font-medium">Dashboard</span>
</a>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-bookmark mr-2"></i>
<span class="font-medium">Bookmarks</span>
</a>
</li>
<li>
<a
pRipple
pStyleClass="@next"
enterClass="hidden"
enterActiveClass="slidedown"
leaveToClass="hidden"
leaveActiveClass="slideup"
class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple"
>
<i class="pi pi-chart-line mr-2"></i>
<span class="font-medium">Reports</span>
<i class="pi pi-chevron-down ml-auto"></i>
</a>
<ul class="list-none py-0 pl-3 pr-0 m-0 hidden overflow-y-hidden transition-all transition-duration-400 transition-ease-in-out">
<li>
<a
pRipple
pStyleClass="@next"
enterClass="hidden"
enterActiveClass="slidedown"
leaveToClass="hidden"
leaveActiveClass="slideup"
class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple"
>
<i class="pi pi-chart-line mr-2"></i>
<span class="font-medium">Revenue</span>
<i class="pi pi-chevron-down ml-auto"></i>
</a>
<ul class="list-none py-0 pl-3 pr-0 m-0 hidden overflow-y-hidden transition-all transition-duration-400 transition-ease-in-out">
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-table mr-2"></i>
<span class="font-medium">View</span>
</a>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-search mr-2"></i>
<span class="font-medium">Search</span>
</a>
</li>
</ul>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-chart-line mr-2"></i>
<span class="font-medium">Expenses</span>
</a>
</li>
</ul>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-users mr-2"></i>
<span class="font-medium">Team</span>
</a>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-comments mr-2"></i>
<span class="font-medium">Messages</span>
<span class="inline-flex align-items-center justify-content-center ml-auto bg-primary border-circle" style="min-width: 1.5rem; height: 1.5rem">3</span>
</a>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-calendar mr-2"></i>
<span class="font-medium">Calendar</span>
</a>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-cog mr-2"></i>
<span class="font-medium">Settings</span>
</a>
</li>
</ul>
</li>
</ul>
<ul class="list-none p-3 m-0">
<li>
<div
pRipple
pStyleClass="@next"
enterClass="hidden"
enterActiveClass="slidedown"
leaveToClass="hidden"
leaveActiveClass="slideup"
class="p-3 flex align-items-center justify-content-between text-600 cursor-pointer p-ripple"
>
<span class="font-medium">APPLICATION</span>
<i class="pi pi-chevron-down"></i>
</div>
<ul class="list-none p-0 m-0 overflow-hidden">
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-folder mr-2"></i>
<span class="font-medium">Projects</span>
</a>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-chart-bar mr-2"></i>
<span class="font-medium">Performance</span>
</a>
</li>
<li>
<a pRipple class="flex align-items-center cursor-pointer p-3 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<i class="pi pi-cog mr-2"></i>
<span class="font-medium">Settings</span>
</a>
</li>
</ul>
</li>
</ul>
</div>
<div class="mt-auto">
<hr class="mb-3 mx-3 border-top-1 border-none surface-border" />
<a pRipple class="m-3 flex align-items-center cursor-pointer p-3 gap-2 border-round text-700 hover:surface-100 transition-duration-150 transition-colors p-ripple">
<p-avatar image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png" shape="circle" />
<span class="font-bold">Amy Elsner</span>
</a>
</div>
</div>
</ng-template>
</p-sidebar>
<p-button (onClick)="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.
Sidebar is a panel component displayed as an overlay at the edges of the screen.
Defines the input properties of the component.
Defines emit that determine the behavior of the component based on a given condition or report the actions that the component takes.
Defines the templates used by the component.