Tooltips

Contextual hover overlays that display supplementary information. Tooltips support four directional placements (top, bottom, left, right), light/dark/glass variants, size tiers, and HTML content. All positioning and visibility are handled via data attributes and CSS — minimal JavaScript is required for initialization.

Placements
Variants & Sizes
Show delay & the dock variant

Immediate tooltips are noisy on chrome you sweep across — a dock, a toolbar — so useTooltips takes a showDelay and any trigger can override it with data-tooltip-delay. This page wires the composable at its default (0ms), so the first two buttons below get their dwell from the attribute alone. Pair the delay with data-tooltip-variant="dock" for the denser frost that reads over ink chrome — the site dock at the edge of this window uses exactly this combination at 520ms.

HTML Content
CSS Variables
VariableDefaultDescription
--vd-tooltip-bgvar(--vd-color-white)Default tooltip background
--vd-tooltip-bg-lightvar(--vd-color-gray-100)Light variant background
--vd-tooltip-bg-darkvar(--vd-color-gray-900)Dark variant background
--vd-tooltip-text-colorvar(--vd-color-gray-900)Default text color
--vd-tooltip-text-color-lightvar(--vd-color-gray-800)Light variant text
--vd-tooltip-text-color-darkvar(--vd-color-white)Dark variant text
--vd-tooltip-padding-y0.5rem (8px)Vertical padding (Fibonacci)
--vd-tooltip-padding-x0.8125rem (13px)Horizontal padding (Fibonacci, ratio ~phi)
--vd-tooltip-arrow-size5pxArrow dimensions (Fibonacci)
--vd-tooltip-max-width233pxMax width (Fibonacci)
--vd-tooltip-z-index1070Stacking above most components
--vd-tooltip-dock-bgcolor-mix(in srgb, #12141a 78%, transparent)Dock variant background (flips to a frosted white in light schemes)
--vd-tooltip-dock-color#f4f4f5Dock variant text color
--vd-tooltip-dock-bordercolor-mix(in srgb, #fff 22%, transparent)Dock variant border
--vd-tooltip-dock-shadowdrop + inset highlightDock variant elevation; the arrow reuses --vd-tooltip-dock-bg
API Reference

Wiring

import { ref } from 'vue';
import { useTooltips, VdTooltip } from "@vanduo-oss/vd3";

const root = ref<HTMLElement | null>(null);

// wires [data-tooltip] inside root; cleanup on unmount
useTooltips(root);

// …or dwell 520ms before showing (dock and toolbar chrome)
useTooltips(root, { showDelay: 520 });

// …or wrap a single trigger with the SFC wrapper component:
// <VdTooltip text="Save changes" position="top">
//   <button class="vd-btn vd-btn-primary">Save</button>
// </VdTooltip>

CSS Classes

ClassDescription
.vd-tooltipBase tooltip element. Positioned absolutely with arrow, shadow, and max-width.
.vd-tooltip-top / [data-placement="top"]Tooltip appears above the trigger.
.vd-tooltip-bottom / [data-placement="bottom"]Tooltip appears below the trigger.
.vd-tooltip-left / [data-placement="left"]Tooltip appears to the left.
.vd-tooltip-right / [data-placement="right"]Tooltip appears to the right.
.vd-tooltip-lightLight gray background with dark text.
.vd-tooltip-darkDark background with white text.
.vd-tooltip-glassFrosted glass background with blur and translucent border.
.vd-tooltip-dockDenser frost than glass, sized for icon-only dock and toolbar chrome. Follows the color scheme (ink in dark, frosted white in light) and cancels the per-placement arrow margin, since useTooltips already positions with a gap.
.vd-tooltip-smCompact padding and smaller font.
.vd-tooltip-lgMore spacious padding and larger font.
.vd-tooltip-htmlAllows HTML content inside the tooltip body.
.vd-tooltip-wrapperOptional inline-block wrapper for positioning context.

Data Attributes

AttributeDescription
data-tooltip="text"Plain text content for the tooltip. Wired by useTooltips(root).
data-tooltip-html="HTML"HTML content for the tooltip. Escaped automatically if the attribute contains plain text with entities.
data-tooltip-placement="top|bottom|left|right"Tooltip position relative to the trigger. Default: top.
data-tooltip-variant="light|dark|glass|dock"Visual style variant. Default: standard (white). dock is the chrome variant.
data-tooltip-size="sm|lg"Size modifier. Default: medium.
data-tooltip-delay="520"Per-trigger hover dwell in ms, overriding the composable's showDelay. Ignored if it is not a non-negative integer.

Composable API

SymbolDescription
useTooltips(root, options?)Composable — wires every [data-tooltip] / [data-tooltip-html] element inside the root ref. Call once in setup().
options.showDelayHover dwell in ms before a tooltip appears. Default 0 (immediate). Any trigger can override it with data-tooltip-delay.
VdTooltipSFC wrapper component — wraps its default slot in an inline <span> and wires useTooltips automatically. Props: text (required string) and position ('top' | 'bottom' | 'left' | 'right', default 'top').
(dynamic triggers)The root is watched with a MutationObserver, so triggers added, removed, or re-attributed after mount bind themselves — no manual rescan.
(automatic cleanup)Hover listeners, the observer, and the tooltip node are removed on component unmount.
v1.4.1 sanitizes tooltip HTML with inline styles disabled by default for framework call sites. Prefer data-tooltip for user-provided text and reserve data-tooltip-html for trusted markup.
Accessibility
  • Tooltips should not contain critical information — ensure the same content is available via visible text or an aria-label on the trigger.
  • For keyboard users, tooltips should appear on focus and hide on blur, not just on hover.
  • Use aria-describedby on the trigger pointing to the tooltip element so screen readers announce the tooltip content when focus lands on it.
  • Tooltips with interactive content (links, buttons) should use a popover or modal instead — tooltips are not focus traps.
  • Avoid tooltips that exceed --vd-tooltip-max-width with large amounts of text. Break complex content into shorter lines or use a popover.
  • Ensure sufficient color contrast for all variant combinations (dark-on-light, light-on-dark, glass text on varying backgrounds).