Panel is a container component with an optional content toggle feature.
import { PanelModule } from 'primeng/panel';
A simple Panel is created with a header property along with the content as children.
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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<p-panel header="Header">
<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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</p-panel>
Content of the panel can be expanded and collapsed using toggleable option, default state is defined with collapsed option. By default, toggle icon is used to toggle the contents whereas setting toggler to "header" enables clicking anywhere in the header to trigger a toggle.
<p-panel header="Header" [toggleable]="true">
<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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</p-panel>
Header and Footers sections can be customized using header and footer templates.
<p-panel>
<ng-template pTemplate="header"> <span class="text-primary font-semibold text-xl">Header</span></ng-template>
Body Content
<ng-template pTemplate="footer"> Footer content here </ng-template>
</p-panel>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-panel | Container element. |
p-panel-titlebar | Header section. |
p-panel-title | Title text of panel. |
p-panel-titlebar-toggler | Toggle icon. |
p-panel-content | Content of panel. |
Toggleable panels use a content toggle button at the header that has aria-controls to define the id of the content section along with aria-expanded for the visibility state. The value to read the button defaults to the value of the header property and can be customized by defining an aria-label or aria-labelledby via the toggleButtonProps property.
The content uses region, defines an id that matches the aria-controls of the content toggle button and aria-labelledby referring to the id of the header.
Key | Function |
---|---|
tab | Moves focus to the next the focusable element in the page tab sequence. |
shift + tab | Moves focus to the previous the focusable element in the page tab sequence. |
enter | Toggles the visibility of the content. |
space | Toggles the visibility of the content. |
API defines helper props, events and others for the PrimeNG Panel module.
Name | Type | Default | Description |
---|---|---|---|
header | string | null | Header text of the panel. |
toggleable | boolean | false | Defines if content of panel can be expanded and collapsed. |
collapsed | boolean | false | Defines the initial state of panel content, supports one or two-way binding as well. |
style | string | null | Inline style of the component. |
styleClass | string | null | Style class of the component. |
expandIcon | string | null | Expand icon of the toggle button. |
collapseIcon | string | null | Collapsed icon of the toggle button. |
showHeader | boolean | true | Specifies if header of panel cannot be displayed. |
transitionOptions | string | 400ms cubic-bezier(0.86, 0, 0.07, 1) | Transition options of the animation. |
toggler | string | icon | Specifies the toggler element to toggle the panel content, valid values are "icon" and "header". |
iconPos | string | right | Position of the icons, valid values are "end", "start" and "center". |
Name | Parameters | Description |
---|---|---|
onBeforeToggle | event.originalEvent: browser event event.collapsed: state as a boolean | Callback to invoke before content toggle. |
onAfterToggle | event.originalEvent: browser event event.collapsed: state as a boolean | Callback to invoke after content toggle. |
Name | Parameters |
---|---|
header | - |
content | - |
icons | - |
headericons | $implicit: collapsed |
footer | - |