OverlayPanel

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 ref and visibility is controlled using toggle, show and hide functions with an event of the target.


<Button type="button" icon="pi pi-image" label="Image" @click="toggle" />

<OverlayPanel ref="op">
    <div class="flex flex-column gap-3 w-25rem">
        <div>
            <span class="font-medium text-900 block mb-2">Share this document</span>
            <InputGroup>
                <InputText value="https://primevue.org/12323ff26t2g243g423g234gg52hy25XADXAG3" readonly class="w-25rem"></InputText>
                <InputGroupAddon>
                    <i class="pi pi-copy"></i>
                </InputGroupAddon>
            </InputGroup>
        </div>
        <div>
            <span class="font-medium text-900 block mb-2">Invite Member</span>
            <InputGroup>
                <Chips disabled></Chips>
                <Button label="Invite" icon="pi pi-users"></Button>
            </InputGroup>
        </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 v-for="member in members" :key="member.name" class="flex align-items-center gap-2">
                    <img :src="`https://primefaces.org/cdn/primevue/images/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>
</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 border-round">
    <div class="relative">
        <img :src="`/images/product/${selectedProduct.image}`" :alt="selectedProduct.name" class="w-4rem shadow-1" class="w-full sm:w-20rem" />
    </div>
    <div class="flex align-items-center justify-content-between mt-3 mb-2">
        <span class="text-900 font-semibold 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="`/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>

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.

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.