vael-ui v0.5.7

Overlays

Layout

Popover

A floating panel anchored to a trigger element. Use it for short forms, pickers or extra detail.

Install

import { Popover } from 'vael-ui'

Playground

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Popover, Button } from 'vael-ui'

const open = ref(false)
</script>

<template>
  <Popover v-model:open="open" open-on-trigger-click>
    <template #trigger>
      <Button>Trigger</Button>
    </template>
    Popover
  </Popover>
</template>

Props

NameTypeDefaultDescription
uiPartial<Record<'positioner' | 'panel', UiPartValue>>Class and style overrides for each part.
triggerElTriggerRefExternal trigger ref: a raw element or a component that exposes el. Use #trigger if the trigger can live here.
side'top' | 'right' | 'bottom' | 'left''bottom'Which side of the trigger the panel opens on.
align'start' | 'end' | 'center''center'How the panel aligns against the trigger along that side.
sideOffsetnumber8Gap between the trigger and the panel, in pixels.
alignOffsetnumber0Shifts the panel along the alignment axis, in pixels.
closeOnEscbooleantrueEscape key closes the panel.
closeOnOutsidebooleantrueClicking outside the panel closes it.
beforeCloseBeforeClose<PopoverCloseReason>Runs before the panel closes. Return true to close it, false to keep it open, or a promise of either, like () => confirmAction(…).result. The panel stays open while the promise is pending.
forceMountbooleanfalseKeeps it mounted while closed, toggled with v-show, so its content keeps its state. vael-ui then leaves its motion to you.
teleportTostring | HTMLElementTeleport target: a CSS selector or element. Wins over container either way.
scrollFadebooleantrueMasks the panel's top/bottom edge as its content scrolls under it, signaling there's more.
panelWidthPanelWidthThe panel's width: 'trigger' for at least its trigger's width, or a width in px or any CSS length ('20rem'). Unset, it fits its content.
containerDOMTargetScopes the popover to an element. It teleports there instead of body, and its Escape handling stays within it. Omit it for a page-level popover.
openOnTriggerClickbooleanfalseClicking the #trigger slot toggles open, and the popover finds the trigger element itself (no setTriggerEl needed). Otherwise you drive open yourself.
motionPopoverMotion<N>How it moves: false for instantly, { spring } to retime the built-in motion, states by part (initial: { panel: { … } }), your targets, or enter/leave hooks for a library. Unset, it follows the nearest ConfigProvider's style.
openbooleanfalseWhether the popover is open.

Events

NameTypeDescription
open-change(value: boolean, details: PopoverOpenChangeDetails)Fires when a close is requested; call details.cancel() to keep the panel open.
after-enter()Fires once it has finished opening.
after-leave()Fires once it has finished closing.
update:open(value: boolean)Fires when open changes (v-model:open).

Slots

NameTypeDescription
default{ close: () => void; open: boolean; isClosing: boolean; cancelClose: () => void; panelEl: HTMLElement | null; placement: string; target: (name: N) => MotionRef; phase: MotionPhase; }Panel content; receives close, open, isClosing, cancelClose, panelEl and placement.
trigger{ open: boolean; setTriggerEl: (el: any) => void; }Trigger markup; bind :ref="setTriggerEl" to position against it. Clicking it does nothing unless you set openOnTriggerClick.

Exposed

NameTypeDescription
panelElHTMLElement | nullPanel element (null while closed).
phaseMotionPhase'entering' | 'entered' | 'leaving' | 'left'.
positionerElHTMLElement | nullPositioning wrapper around the panel (null while closed).
placementPlacementResolved placement after flipping, e.g. 'bottom-start'.
positionerStyleRecord<string, string>Computed position styles applied to the positioner.
isClosingbooleantrue while a beforeClose close is pending.
close() => voidCloses the panel, running @open-change and beforeClose first.
cancelClose() => voidCancels a close pending in beforeClose and keeps the panel open.

Motion New

Popover's motion: values or hooks for positioner and panel, how it opens and closes (morph, surface, resize) and swapped content. false turns it off.

<Popover
  :motion="{
    initial: { panel: { opacity: 0, y: 8, scale: 0.98 } },
    spring: { damping: 0.85, response: 0.35 },
  }"
/>
NameTypeDescription
initialexitpositionerpanelSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
morphlinkedexitOrder'trigger' | Record<string, LinkedMotion> | 'reverse'morph: 'trigger' grows it out of the element that opened it. linked moves other elements with it, such as the page receding behind it. exitOrder: 'reverse' closes its children first.
swapresize'sync' | 'wait' | booleanContent that changes while it's open crossfades ('sync') or waits for the old view to leave ('wait'), and the box eases to its new size unless resize: false.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

KeyAction
EscapeCloses the popover, unless closeOnEsc is false.
TabMoves focus from the trigger into the panel; past the last element, it closes the panel and moves to the element after the trigger.
ShiftTabMoves focus from the first element in the panel back to the trigger and closes the panel.
  • The panel has no role and isn’t a focus trap. For interactive content, pass role="dialog" and an aria-label; attributes go on the panel.
  • A button in the #trigger slot gets aria-expanded, and aria-controls while open. A trigger passed with triggerEl gets neither.
  • Opening doesn’t move focus. If focus is in the panel when it closes, it returns to the trigger.
  • Moving focus outside the panel closes it, unless closeOnOutside is false.