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.
vue
<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.
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 |
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 |
The following API details are for the usePopover composable.
Functions
usePopover
(options?: PopoverOptions) => PopoverReturnOptions
isOpen
Ref<boolean, boolean> | undefinedExternal ref for bidirectional open state (e.g., from defineModel)
Was this page helpful?