import OverlayPanel from 'primevue/overlaypanel';
<script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>
<script src="https://unpkg.com/primevue@^3/overlaypanel/overlaypanel.min.js"></script>
OverlayPanel is accessed via its reference where visibility is controlled using toggle, show and hide methods.
<Button type="button" label="Toggle" @click="toggle" />
<OverlayPanel ref="op">
<img src="/images/nature/nature1.jpg" alt="Nature Image">
</OverlayPanel>
toggle(event) {
this.$refs.op.toggle(event);
}
Clicking outside the overlay hides the panel, setting dismissable to false disables this behavior. Additionally enabling showCloseIcon property displays a close icon at the top right corner to close the panel.
<OverlayPanel ref="op" :showCloseIcon="true" :dismissable="true">
<img src="/images/nature/nature1.jpg" alt="Nature Image">
</OverlayPanel>
OverlayPanel width can be adjusted per screen size with the breakpoints option. In example below, default width is set to 450px and below 961px, width would be 75vw and finally below 641px width becomes 100%. The value of breakpoints should be an object literal whose keys are the maximum screen sizes and values are the widths per screen.
<OverlayPanel ref="op" :breakpoints="{'960px': '75vw', '640px': '100vw'}" :style="{width: '450px'}">
Content
</OverlayPanel>
Name | Type | Default | Description |
---|---|---|---|
dismissable | boolean | true | Enables to hide the overlay when outside is clicked. |
showCloseIcon | boolean | false | When enabled, displays a close icon at top right corner. |
appendTo | string | body | A valid query selector or an HTMLElement to specify where the overlay gets attached. |
baseZIndex | number | 0 | Base zIndex value to use in layering. |
autoZIndex | boolean | true | Whether to automatically manage layering. |
breakpoints | object | null | Object literal to define widths per screen size. |
ariaCloseLabel | string | close |
Aria label of the close icon.
Deprecated: aria.close can be used in defaults to PrimeVue |
Name | Parameters | Description |
---|---|---|
toggle |
event: Browser event target: Optional target if event.currentTarget should not be used |
Toggles the visibility of the overlay. |
show |
event: Browser event target: Optional target if event.currentTarget should not be used |
Shows the overlay. |
hide | - | Hides the overlay. |
Name | Parameters | Description |
---|---|---|
show | - | Callback to invoke when the overlay is shown. |
hide | - | Callback to invoke when the overlay is hidden. |
Following is the list of structural style classes, for theming classes visit
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. |
None.