OverlayPanel, also known as Popover, is a container component that can overlay other components on page.
import OverlayPanel from 'primevue/overlaypanel';
OverlayPanel is accessed via its reference and visibility is controlled using toggle, show and hide methods with an event of the target.
<Button type="button" icon="pi pi-image" label="Image" @click="toggle" />
<OverlayPanel ref="op">
<img src="https://primefaces.org/cdn/primevue/images/product/bamboo-watch.jpg" alt="Bamboo Watch" />
</OverlayPanel>
An example that displays a DataTable inside a popup to select an item.
<Toast />
<Button type="button" icon="pi pi-search" :label="selectedProduct ? selectedProduct.name : 'Select a Product'" @click="toggle" aria-haspopup="true" aria-controls="overlay_panel" />
<div v-if="selectedProduct" class="p-5 surface-card shadow-2 border-round">
<div class="relative">
<img :src="`https://primefaces.org/cdn/primevue/images/product/${selectedProduct.image}`" :alt="selectedProduct.name" class="w-4rem shadow-1" />
</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>
<OverlayPanel ref="op" appendTo="body">
<DataTable v-model:selection="selectedProduct" :value="products" selectionMode="single" :paginator="true" :rows="5" @row-select="onProductSelect">
<Column field="name" header="Name" sortable style="width: 50%"></Column>
<Column header="Image" style="width: 20%">
<template #body="slotProps">
<img :src="`https://primefaces.org/cdn/primevue/images/product/${selectedProduct.image}`" :alt="slotProps.data.image" class="w-4rem shadow-1" />
</template>
</Column>
<Column field="price" header="Price" sortable style="width: 30%">
<template #body="slotProps">
{{ slotProps.data.price }}
</template>
</Column>
</DataTable>
</OverlayPanel>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-overlaypanel | Container element. |
p-overlaypanel-content | Content of the panel. |
p-overlaypanel-close | Close icon. |
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.
OverlayPanel adds aria-expanded state attribute and aria-controls to the trigger so that the relation between the trigger and the popup is defined.
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.
Key | Function |
---|---|
tab | Moves focus to the next the focusable element within the popup. |
shift + tab | Moves focus to the previous the focusable element within the popup. |
escape | Closes the popup and moves focus to the trigger. |
Key | Function |
---|---|
enter | Closes the popup and moves focus to the trigger. |
space | Closes the popup and moves focus to the trigger. |