usePopover
A composable for native popover API behavior with CSS anchor positioning.
Usage
usePopover manages a popover’s open/close state, generates CSS anchor positioning styles, and synchronizes reactive state with native popover toggle events. Spread anchorStyles on the activator, contentAttrs and contentStyles on the content element, and call attach() to wire up the native popover lifecycle.
<script setup lang="ts">
import { usePopover } from '@vuetify/v0'
import { useTemplateRef } from 'vue'
const content = useTemplateRef('content')
const {
isOpen,
toggle,
attach,
anchorStyles,
contentAttrs,
contentStyles,
} = usePopover({ positionArea: 'bottom' })
attach(content)
</script>
<template>
<button :style="anchorStyles" @click="toggle">
{{ isOpen ? 'Close' : 'Open' }}
</button>
<div
ref="content"
v-bind="contentAttrs"
:style="contentStyles"
>
Popover content
</div>
</template>Architecture
usePopover builds on useEventListener for native toggle event synchronization. It is a standalone composable — not part of the compound Popover component — making it ideal for building select, combobox, tooltip, and menu components directly.
Options
| Option | Type | Default | Notes |
|---|---|---|---|
id | string | auto | Base ID for anchor name and popover id. Auto-generated if not provided |
positionArea | string | 'bottom' | CSS position-area value — controls where the content appears relative to the anchor |
positionTry | string | 'most-width bottom' | CSS position-try-fallbacks value — fallback positions when the primary area overflows |
isOpen | Ref<boolean> | — | External ref for bidirectional open state (e.g., from defineModel) |
openDelay | MaybeRefOrGetter<number> | 0 | Milliseconds to wait before opening the popover |
closeDelay | MaybeRefOrGetter<number> | 0 | Milliseconds to wait before closing the popover |
Reactivity
| Property/Method | Reactive | Notes |
|---|---|---|
isOpen | ShallowRef, tracks whether the popover is open | |
open() | - | Open the popover |
close() | - | Close the popover |
toggle() | - | Toggle open/close |
cancel() | - | Cancel any pending open or close transition |
attach(el) | - | Wire native show/hide watch + toggle event sync to a content element |
anchorStyles | Readonly Ref, CSS anchor-name for the activator element | |
contentAttrs | Readonly Ref, id and popover attribute for the content element | |
contentStyles | Readonly Ref, CSS anchor positioning styles for the content element |
Examples
Open the menu and choose an action. Click outside or press Escape to dismiss.
FAQ
Reach for usePopover when you want full control over a select, combobox, tooltip, or menu surface built from your own markup. Use the Popover component when its slots and transitions are enough.
attach(el) wires the native popover’s toggle event back into isOpen. Without it, the browser’s light dismiss (outside click, Escape) would close the popover but your reactive state would drift out of sync.
No. contentAttrs registers a native auto popover, so the browser handles light dismiss — outside click and Escape — for free. Reach for useClickOutside only when you wire dismissal manually instead of using the native popover.
Pass openDelay and closeDelay (ms) in the options. Call cancel() to abort a pending open or close transition before it fires.
Set positionArea (e.g. 'bottom') for the primary placement and positionTry for the fallback positions the browser flips to when that area overflows — CSS anchor positioning handles it with no JavaScript layout math.