vael-ui v0.5.7

Overlays

Layout

Tooltip

A short label that appears on hover or focus. Use it to name an icon button or explain a control.

Install

import { Tooltip } from 'vael-ui'

Playground

Placement, behaviour and animation

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

const open = ref(false)
</script>

<template>
  <Tooltip v-model:open="open">
    <template #trigger="{ setTriggerEl }">
      <Button :ref="setTriggerEl">Trigger</Button>
    </template>
    Tooltip
  </Tooltip>
</template>

Props

NameTypeDefaultDescription
triggerElTriggerRefExternal trigger ref: a raw element or a component that exposes el.
side'top' | 'right' | 'bottom' | 'left''top'Which side of the trigger the tooltip opens on.
align'start' | 'end' | 'center''center'How the tooltip aligns against the trigger along that side.
sideOffsetnumber8Gap between the trigger and the tooltip, in pixels.
alignOffsetnumber0Shifts the tooltip along the alignment axis, in pixels.
followbooleanfalseWhile open, the tooltip tracks a mouse or pen along the trigger's edge, clamped to it, in place of align and alignOffset: for a wide trigger, such as a timeline bar.
openDelaynumber400Delay before a cold open, in milliseconds. Warm-group opens (another tooltip visible or recently hidden) are instant.
closeDelaynumber100Grace period after the pointer leaves, in milliseconds, so it can move onto the tooltip.
interactivebooleantrueHovering the tooltip itself keeps it open, so its text can be selected. Keyboard users can't reach it, so put links and buttons in a Popover.
closeOnEscbooleantrueEscape key closes the tooltip.
beforeCloseBeforeClose<TooltipCloseReason>Runs before the tooltip closes. Return true to close it, false to keep it open, or a promise of either, like () => confirmAction(…).result. The tooltip 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.
motionTooltipMotionHow it moves. false shows and hides it at once. An object moves it your way, like Popover's: values for the panel part, { spring }, or enter / leave hooks. A warm open, right after another tooltip, stays instant either way.
teleportTostring | HTMLElement'body'Teleport target: a CSS selector or element.
uiPartial<Record<'positioner' | 'panel', UiPartValue>>Class and style overrides for each part. Set --ui-tooltip-bg and --ui-tooltip-color on panel to recolour it.
openbooleanfalseWhether the tooltip is open.

Events

NameTypeDescription
open-change(value: boolean, details: TooltipOpenChangeDetails)Fires when a close is requested; call details.cancel() to keep the tooltip open.
update:open(value: boolean)Fires when open changes (v-model:open).

Slots

NameTypeDescription
default{ open: boolean; isClosing: boolean; }Tooltip content; receives open and isClosing.
trigger{ open: boolean; setTriggerEl: (el: any) => void; }Trigger markup; bind :ref="setTriggerEl" to the triggering element.

Exposed

NameTypeDescription
panelElHTMLElement | nullPanel element (null while closed).
positionerElHTMLElement | nullPositioning wrapper around the panel (null while closed).
placementPlacementResolved placement after flipping, e.g. 'top' or 'bottom-start'.
positionerStyleRecord<string, string>Computed position styles applied to the positioner.
isClosingbooleantrue while a beforeClose close is pending.
show() => voidOpens the tooltip immediately, skipping openDelay; revives it if it's mid-close.
hide() => voidCloses the tooltip, running @open-change and beforeClose first.
cancelClose() => voidCancels a close pending in beforeClose and keeps the tooltip open.

Motion New

Tooltip's box: values or hooks for its parts, like Popover's. Warm opens stay instant.

<Tooltip
  :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.
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

Follows the Tooltip pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
TabOpens the tooltip when keyboard focus reaches the trigger, and closes it when focus leaves.
EscapeCloses the tooltip without closing a dialog or menu around it.
  • The panel has role="tooltip". While it’s open, the trigger’s aria-describedby includes its id, and your own ids stay. A tooltip that only repeats the trigger’s name isn’t added, so it isn’t read twice.
  • It opens on :focus-visible only, so a mouse click doesn’t open it. On touch, a 500 ms long press opens it, and it closes 1.5 s after you lift your finger or when you tap elsewhere.
  • The tooltip describes the trigger but doesn’t name it. An icon-only trigger still needs an aria-label. v-tooltip with text sets that aria-label on a button or link with no name of its own.
  • Keyboard users can’t move into the tooltip. Put links and buttons in a Popover.
  • The trigger must be focusable for keyboard users to reach the tooltip.