Popover
A Popover is a non-disruptive container that is overlaid on a web page or app, positioned near its trigger, in order to present necessary information and tasks.
Name | Value |
---|---|
Props | |
title | |
icon | |
useCloseButton | |
placement | Choose an option |
stackedActions | |
usePrimaryAction | |
primaryActionLabel | |
primaryActionType | |
useDefaultAction | |
defaultActionLabel | |
Slots | |
default | |
View | |
Reading direction | |
Note: For icon properties, the relevant icon also needs to be imported from the @wikimedia/codex-icons package. See the usage documentation for more information. |
Overview
When to use Popover
The Popover component is intended to be used with other components such as a ToggleButton or Link. The Popover is displayed when the user interacts with the corresponding trigger element.
Use a ToggleButton as a trigger to emphasize what opened the Popover, setting the ToggleButton into its toggled state when triggering the Popover.
Use a Link as a trigger when the Popover is meant to serve as a preview for what pressing the link will present.
Popovers facilitate communication between the system and user. They perform best when used for additional information or as a workflow within a bigger task, as they don’t require loading a new page and keep actions in context.
Popovers differ from Dialogs as they are not as disruptive, since the context of the page around the Popover remains, as there is no visual overlay on the page. That being said, they should be used sparingly and only when necessary, since they inherently hide content and require an additional action to reveal it.
Use the Popover component when:
- Additional information needs to be displayed and separated from the page content.
- It is helpful to have the context of the page still within view.
Avoid using Popover when:
- The information can be displayed within the main interface.
- The content is long or complex, like a form with numerous fields.
- Typed input is required from the user.
- Components that take up a large amount of space need to be used in the content.
- The information being shown is a very brief message or explanation for an element on the page. Instead, use Tooltip.
About Popover
Popover includes the following elements.
Header
The Popover header can contain a decorative icon, title, or standard text. A quiet, icon-only Button may be used to close the Popover.
Body
Interactive types of content or components can be included within the Popover’s body—typically Fields or other form element types of components.
Avoid using Cards, other elevated components, or components requiring a lot of space within the Popover.
Footer
Action buttons should appear at the start of the Popover. A primary Button (either progressive or destructive) is used to indicate the main action. A normal neutral Button can be used to indicate a default action (e.g. “Cancel”). Additionally, icon-only Buttons can be used as needed.
Stack action buttons based on text length when needed, placing the primary button on top.
Don't stack action buttons when they can be placed side by side.
Arrow
Popovers have an arrow which points to the trigger.
Examples
Basic usage
This example includes text, a custom placement, and the ability to manually dismiss the Popover.
Use the header to align standard text content to the dismiss action.
Developer notes
Create a template ref for the trigger element, and then pass that ref to the anchor
prop. The anchor
prop is required to correctly position the Popover.
Ensure the toggle button's on/off state and the popover's visibility is synchronized via v-model
.
Usage in TypeScript
Vue 3.5 introduced the useTemplateRef()
composable to simplify the creation of template refs in Vue components using the Composition API. If you are using TypeScript, consider annotating the types for any template refs like this:
// Basic component typing with ComponentPublicInstance.
const anchorRef = useTemplateRef<ComponentPublicInstance>("my-anchor-id");
More information on typing component template refs can be found in the Vue.js docs.
Article preview
This example uses the hover
trigger since a link leads to a new page or section.
Use images and other media as needed to convey visual information in the Popover.
Use
hover
as a trigger only for elements which have a separatepress
action, such as a link.
Did you know?
- ... that in 1994 Kazuyoshi Akiyama conducted the Tokyo Symphony Orchestra in the first performance of Schoenberg's Moses und Aron with Japanese musicians?
- ... that the impact of the Charlottetown meteorite was the first to be recorded on video and audio?
- ... that the Fun Lounge police raid is considered the main cause for the formation of Mattachine Midwest , a gay rights group in Chicago?
- ... that the 8-Bit Big Band won Nintendo their first Grammy Award?
- ... that a person required intensive care after being splashed with salt water by a beluga whale?
- ... that Alia Fischer led the first women's college basketball team to achieve back-to-back undefeated seasons?
Developer notes
The example has multiple anchor tags that displays Popover content when hovered or focused. The trigger element and Popover content is dynamically updated based on where the event took place.
- Assign each trigger element e.g. anchor tag a template ref, and store them in the
triggerElements
array. - To show and hide the Popover on hover and focus, add
mouseover
,focus
,mouseleave
, andblur
event listeners to the anchor tags that trigger a Popover.
Technical implementation
Vue usage
Props
Prop name | Description | Type | Default |
---|---|---|---|
anchor | The triggering element that opens and closes the popover. This should be a template ref, which can be either an HTML element or a Vue component. This must be provided so the popover can be positioned relative to the triggering element. | HTMLElement|ComponentPublicInstance|null | null |
open | Whether the popover is visible. Should be provided via a v-model:open binding in the parent scope. | boolean | false |
title | Title text at the top of the popover. | string | '' |
icon | Icon displayed at the start of the popover. | Icon | '' |
useCloseButton | Add an icon-only close button to the popover header. | boolean | false |
closeButtonLabel | Visually-hidden label text for the icon-only close button in the header. Omit this prop to use the default value, "Close". | string | 'Close' |
primaryAction | Primary user action. This will display a primary button with the specified action (progressive or destructive). | PrimaryModalAction | null |
defaultAction | Default user action. This will display a normal button. | ModalAction | null |
stackedActions | Whether action buttons should be vertically stacked and 100% width. | boolean | false |
renderInPlace | Whether to disable the use of teleport and render the Popover in its original location in the document. | boolean | false |
placement | Positioning options for the Popover. | Placement | 'bottom' |
Events
Event name | Properties | Description |
---|---|---|
primary | When the primary action button is clicked. | |
default | When the default action button is clicked. | |
update:open | newValue boolean - The new open/close state (true for open, false for closed) | When the open/close state changes, e.g. when the close button is clicked. |
Slots
Name | Description | Bindings |
---|---|---|
header | Customizable Popover header. | |
default | Popover body content. | |
footer | Customizable Popover footer. |
Keyboard navigation
Key | Function |
---|---|
Tab | It moves focus to the next interactive element and, if that element is outside the Popover, it closes the Popover. |
Shift + Tab | It moves focus to the previous interactive element and, if that element is outside the Popover, it closes the Popover. |
Esc | It closes the Popover. |