OverlayPanel

OverlayPanel, also known as Popover, is a container component that can overlay other components on page.


import { OverlayPanelModule } from 'primeng/overlaypanel';

OverlayPanel is accessed via its reference and visibility is controlled using toggle, show and hide methods with an event of the target.


<p-button (onClick)="op.toggle($event)" icon="pi pi-share-alt" label="Share" />
    <p-overlayPanel #op>
        <div class="flex flex-column gap-3 w-25rem">
            <div>
                <span class="font-medium text-900 block mb-2">Share this document</span>
                <p-inputGroup>
                    <input pInputText value="https://primeng.org/12323ff26t2g243g423g234gg52hy25XADXAG3" readonly class="w-25rem" />
                    <p-inputGroupAddon>
                        <i class="pi pi-copy"></i>
                    </p-inputGroupAddon>
                </p-inputGroup>
            </div>
            <div>
                <span class="font-medium text-900 block mb-2">Invite Member</span>
                <div class="flex">
                    <p-chips disabled />
                    <p-button label="Invite" icon="pi pi-users" />
                </div>
            </div>
            <div>
                <span class="font-medium text-900 block mb-2">Team Members</span>
                <ul class="list-none p-0 m-0 flex flex-column gap-3">
                    <li *ngFor="let member of members" class="flex align-items-center gap-2">
                        <img [src]="'https://primefaces.org/cdn/primeng/images/demo/avatar/' + member.image" style="width: 32px" />
                        <div>
                            <span class="font-medium">{{ member.name }}</span>
                            <div class="text-sm text-color-secondary">{{ member.email }}</div>
                        </div>
                        <div class="flex align-items-center gap-2 text-color-secondary ml-auto text-sm">
                            <span>{{ member.role }}</span>
                            <i class="pi pi-angle-down"></i>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </p-overlayPanel>

An example that displays a DataTable inside a popup to select an item.

Bamboo Watch
Bamboo Watch$65
Accessories

<p-toast />
<p-button 
    (onClick)="op.toggle($event)" 
    icon="pi pi-search" 
    [label]="selectedProduct ? selectedProduct.name : 'Select a Product'" />
<div *ngIf="selectedProduct" class="p-5 surface-card shadow-2 border-round">
    <div class="relative">
        <img 
            src="https://primefaces.org/cdn/primeng/images/demo/product/{{ selectedProduct.image }}" 
            [alt]="selectedProduct.name" />
    </div>
    <div class="flex align-items-center justify-content-between mt-3 mb-2">
        <span class="text-900 font-medium text-xl">
            {{ selectedProduct.name }}
        </span>
        <span class="text-900 text-xl ml-3">
            {{ '$' + selectedProduct.price }}
        </span>
    </div>
    <span class="text-600">
        {{ selectedProduct.category }}
    </span>
</div>
<p-overlayPanel #op [style]="{ width: '450px' }" [showCloseIcon]="true">
    <ng-template pTemplate="content">
        <p-table 
            [value]="products" 
            selectionMode="single" 
            [(selection)]="selectedProduct" 
            (onRowSelect)="onRowSelect($event, op)" 
            [paginator]="true" 
            [rows]="5" 
            responsiveLayout="scroll">
                <ng-template pTemplate="header">
                    <tr>
                        <th pSortableColumn="name">
                            Name <p-sortIcon field="name" />
                        </th>
                        <th>Image</th>
                        <th pSortableColumn="price">
                            Price <p-sortIcon field="price" />
                        </th>
                    </tr>
                </ng-template>
                <ng-template pTemplate="body" let-rowData let-product>
                    <tr [pSelectableRow]="rowData">
                        <td>
                            {{ product.name }}
                        </td>
                        <td>
                            <img 
                                src="https://primefaces.org/cdn/primeng/images/demo/product/{{ product.image }}" 
                                [alt]="product.image" 
                                class="w-5rem shadow-2" />
                        </td>
                        <td>{{ product.price }}</td>
                    </tr>
                </ng-template>
        </p-table>
    </ng-template>
</p-overlayPanel>

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

NameElement
p-overlaypanelContainer element.
p-overlaypanel-contentContent of the panel.
p-overlaypanel-closeClose icon.

Screen Reader

OverlayPanel component uses dialog role and since any attribute is passed to the root element you may define attributes like aria-label or aria-labelledby to describe the popup contents. In addition aria-modal is added since focus is kept within the popup.

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. OverlayPanel adds aria-expanded state attribute and aria-controls to the trigger so that the relation between the trigger and the popup is defined.

OverlayPanel Keyboard Support

When the popup gets opened, the first focusable element receives the focus and this can be customized by adding autofocus to an element within the popup.

KeyFunction
tabMoves focus to the next the focusable element within the popup.
shift + tabMoves focus to the previous the focusable element within the popup.
escapeCloses the popup and moves focus to the trigger.

Close Button Keyboard Support

KeyFunction
enterCloses the popup and moves focus to the trigger.
spaceCloses the popup and moves focus to the trigger.