--- title: "MazPopover" description: "MazPopover is a versatile Vue component for displaying content in overlays that bypass overflow constraints of parent elements" package: "maz-ui" url: "https://maz-ui.com/components/maz-popover" --- # MazPopover > MazPopover is a versatile Vue component for displaying content in overlays that bypass overflow constraints of parent elements - Package: `maz-ui` - Import: `import MazPopover from 'maz-ui/components/MazPopover'` - Nuxt: auto-imported by `@maz-ui/nuxt`, no import needed in a Nuxt app - Web: https://maz-ui.com/components/maz-popover ## Basic usage ```vue ``` ## Adaptive trigger The `adaptive` trigger mode automatically adapts to the user's device: - **Desktop**: Uses hover behavior (mouseenter/mouseleave) - **Mobile/Touch devices**: Uses click behavior This provides the best user experience across all devices without requiring manual configuration. ```vue ``` ## Positions **Tip:** The position prop is used to position the popover relative to the trigger. The chosen position will force the popover to be displayed in the chosen position. ```vue ``` ## Advanced positions ```vue ``` ## Prefer position and fallback position **Tip:** The prefer-position and fallback-position props are used to position the popover relative to the trigger. The prefer-position is the position that will be used if it's available, and the fallback-position is the position that will be used if the prefer-position is not available. When you not specify a fallback position, the popover will fallback on the best position available. ```html

This popover will prefer the top position, but if it's not available, it will fallback to the bottom position.

``` ## Colors ```vue ``` ## Tooltip role A directive is available to more easily add a tooltip to an element, see [vTooltip](../directives/tooltip.md) for more information. ```vue ``` ## Controlled popover ```vue ``` ## Menu example ```vue ``` ## Keep open on hover > With this option, the popover will stay open when you hover over it (a timeout is used to close the popover after a certain time). ```vue ``` ## Form example ```vue ``` ## Configuration options ```vue ``` ## Events ```vue ``` ## Position values - `auto` - Automatically choose best position - `top`, `bottom`, `left`, `right` - Basic positions - `top-start`, `top-end` - Top with start/end alignment - `bottom-start`, `bottom-end` - Bottom with start/end alignment - `left-start`, `left-end` - Left with start/end alignment - `right-start`, `right-end` - Right with start/end alignment ## Accessibility MazPopover follows WAI-ARIA guidelines: - **Focus management**: Automatically manages focus when opening/closing - **Keyboard navigation**: Supports Escape key and Tab navigation - **ARIA attributes**: Proper `role`, `aria-modal`, `aria-labelledby`, etc. - **Screen reader support**: Appropriate roles for different use cases - **Trigger ARIA on the real control**: `aria-expanded`, `aria-haspopup` and `aria-controls` are set on the interactive element of the `trigger` slot (your button, link...), never on a wrapper around it. ARIA attributes you set yourself on that element are kept, and a `combobox` keeps managing its own state. When the slot has no interactive element, the wrapper becomes a focusable `button` (Enter / Space toggle the popover). ### Best practices - Use `role="tooltip"` for simple informational overlays - Use `role="dialog"` for interactive content - Provide meaningful `aria-labelledby` or `aria-describedby` attributes - Ensure trigger elements are focusable and have proper labels ## MazPopover API `import MazPopover from 'maz-ui/components/MazPopover'` ### Props - `model-value` (`boolean`, default: `false`, `v-model`): Controls the popover open state. - `position` (`MazPopoverPosition`, default: `"auto"`): Position of the popover relative to trigger - Position of the popover relative to trigger. Values: `'auto'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-start'`, `'top-end'`, `'bottom-start'`, `'bottom-end'`, `'left-start'`, `'left-end'`, `'right-start'`, `'right-end'` (non exhaustive). - `prefer-position` (`MazPopoverPreferPosition`, default: `'bottom-start'`): Preferred position of the popover relative to trigger when auto position is used - Preferred position of the popover relative to trigger. Values: `'auto'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-start'`, `'top-end'`, `'bottom-start'`, `'bottom-end'`, `'left-start'`, `'left-end'`, `'right-start'`, `'right-end'` (non exhaustive). - `fallback-position` (`MazPopoverFallbackPosition`, default: `auto`): Fallback position of the popover relative to trigger when prefer position is not visible - Fallback position of the popover relative to trigger. Values: `'auto'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-start'`, `'top-end'`, `'bottom-start'`, `'bottom-end'`, `'left-start'`, `'left-end'`, `'right-start'`, `'right-end'` (non exhaustive). - `trigger` (`MazPopoverTrigger`, default: `"click"`): How the popover is triggered - How the popover is triggered. 'adaptive' uses hover on desktop and click on mobile. Values: `'click'`, `'hover'`, `'manual'`, `'adaptive'` (non exhaustive). - `role` (`MazPopoverRole`, default: `"dialog"`): ARIA role for accessibility - ARIA role for accessibility. Values: `'dialog'`, `'tooltip'` (non exhaustive). - `aria-label` (`string`): ARIA label for the popover. - `announce-changes` (`boolean`, default: `false`): Announce content changes to screen readers. - `disabled` (`boolean`, default: `false`): Disables the popover - Disables the popover. - `offset` (`number`, default: `8`): Distance between trigger and popover in pixels. - `delay` (`number`, default: `0`): Delay before showing/hiding in milliseconds. - `hover-delay` (`number`, default: `150`): Delay before closing on hover in milliseconds. - `transition` (`string`, default: `"scale-pop"`): CSS transition name for animations - 'scale-pop' | 'scale-fade' for default transitions. 'scale-pop' is a pop effect, 'scale-fade' is a fade effect. Values: `'scale-pop'`, `'scale-fade'`, `'string'` (non exhaustive). - `teleport-to` (`string`, default: `"body"`): Teleport target selector. - `overlay-class` (`ClassValue`): Additional CSS classes for the overlay wrapper. - `panel-class` (`ClassValue`): Additional CSS classes for the popover panel. - `panel-style` (`StyleValue`): Inline styles for the popover panel. - `close-on-click-outside` (`boolean`, default: `true`): Close popover when clicking outside. - `close-on-escape` (`boolean`, default: `true`): Close popover when pressing Escape key. - `persistent` (`boolean`, default: `false`): Prevent auto-close (ignores click outside and escape key). - `id` (`string`): Custom ID for the popover element. - `aria-labelledby` (`string`): ARIA labelledby attribute for accessibility. - `aria-describedby` (`string`): ARIA describedby attribute for accessibility. - `color` (`"primary" | "secondary" | "accent" | "info" | "success" | "warning" | "destructive" | "contrast" | "transparent" | "surface"`, default: `"surface"`): Color variant of the popover. - `trap-focus` (`boolean`, default: `true`): Trap focus inside the popover. - `keep-open-on-hover` (`boolean`, default: `false`): Keep popover open when hovering over the panel. - `block` (`boolean`, default: `false`): The popover will be full width of the trigger. - `position-reference` (`string | HTMLElement`): CSS selector or element reference to use for positioning calculations - When provided, the popover will position relative to this element instead of the trigger Useful for components with labels where you want to position relative to the actual input. ### Events - `@update:model-value` (payload: `value: boolean`): Emitted when popover state changes - `@open`: Emitted when popover opens - `@close`: Emitted when popover closes - `@toggle` (payload: `value: boolean`): Emitted when popover toggles - `@update:modelValue` (payload: `value: boolean`) - `@after-close-animation`: Emitted after the close animation ### Slots - `#trigger`: Trigger element content Bindings: `open: () => void` (Function to open the popover), `close: () => void` (Function to close the popover), `toggle: () => void` (Function to toggle the popover), `isOpen: boolean` (Current open state of the popover), `trigger: "click" | "hover" | "manual"` (The trigger type). - `#default`: Popover content Bindings: `open: () => void` (Function to open the popover), `close: () => void` (Function to close the popover), `toggle: () => void` (Function to toggle the popover), `isOpen: true` (Current open state of the popover). ### Exposed (template ref) - `open`: Open the popover - `close`: Close the popover - `toggle`: Toggle the popover - `isOpen`: Check if the popover is open - `updatePosition`: Update the popover position - `panelRef`: Panel reference - `onTransitionAfterLeave`