Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

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.

Popover Architecture

Use controls to zoom and pan. Click outside or press Escape to close.

Popover Architecture

Options

OptionTypeDefaultNotes
idstringautoBase ID for anchor name and popover id. Auto-generated if not provided
positionAreastring'bottom'CSS position-area value — controls where the content appears relative to the anchor
positionTrystring'most-width bottom'CSS position-try-fallbacks value — fallback positions when the primary area overflows
isOpenRef<boolean>External ref for bidirectional open state (e.g., from defineModel)
showDelaynumber0Milliseconds to wait before showing the popover (hover/focus use cases)
hideDelaynumber0Milliseconds to wait before hiding the popover (prevents premature close on mouse leave)

Reactivity

Property/MethodReactiveNotes
isOpenShallowRef, 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
anchorStylesReadonly Ref, CSS anchor-name for the activator element
contentAttrsReadonly Ref, id and popover attribute for the content element
contentStylesReadonly Ref, CSS anchor positioning styles for the content element

Examples

CSS Anchor Positioning

A popover positioned relative to its trigger using the native Popover API and CSS anchor positioning, demonstrating anchorStyles, contentAttrs, and contentStyles.

Anchor Positioned

This popover uses the native Popover API with CSS anchor positioning. It flips automatically when near viewport edges.

Closed

API Reference

The following API details are for the usePopover composable.

Functions

usePopover

(options?: PopoverOptions) => PopoverReturn

Options

id

string | undefined

Auto-generated if not provided

positionArea

string | undefined

CSS position-area value

Default: 'bottom'

positionTry

string | undefined

CSS position-try-fallbacks value

Default: 'most-width bottom'

isOpen

Ref<boolean, boolean> | undefined

External ref for bidirectional open state (e.g., from defineModel)

showDelay

number | undefined

Delay in ms before showing the popover.

Default: 0

hideDelay

number | undefined

Delay in ms before hiding the popover.

Default: 0

Properties

isOpen

Ref<boolean, boolean>

Whether the popover is open

id

string

Unique ID for the popover

anchorStyles

Readonly<Ref<Record<string, string>, Record<string, string>>>

Styles to spread on the activator element (anchor-name)

contentAttrs

Readonly<Ref<{ id: string; popover: ""; }, { id: string; popover: ""; }>>

Attrs to spread on the content element (id, popover)

contentStyles

Readonly<Ref<Record<string, string>, Record<string, string>>>

Styles to spread on the content element (positioning)

Methods

open

() => void

Open the popover

close

() => void

Close the popover

toggle

() => void

Toggle open/close

attach

(el: MaybeRefOrGetter<HTMLElement | null | undefined>) => void

Attach to a content element — wires show/hide watch + toggle event sync

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/