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
| Variable | Default | Description |
|---|---|---|
--vd-tooltip-bg | var(--vd-color-white) | Default tooltip background |
--vd-tooltip-bg-light | var(--vd-color-gray-100) | Light variant background |
--vd-tooltip-bg-dark | var(--vd-color-gray-900) | Dark variant background |
--vd-tooltip-text-color | var(--vd-color-gray-900) | Default text color |
--vd-tooltip-text-color-light | var(--vd-color-gray-800) | Light variant text |
--vd-tooltip-text-color-dark | var(--vd-color-white) | Dark variant text |
--vd-tooltip-padding-y | 0.5rem (8px) | Vertical padding (Fibonacci) |
--vd-tooltip-padding-x | 0.8125rem (13px) | Horizontal padding (Fibonacci, ratio ~phi) |
--vd-tooltip-arrow-size | 5px | Arrow dimensions (Fibonacci) |
--vd-tooltip-max-width | 233px | Max width (Fibonacci) |
--vd-tooltip-z-index | 1070 | Stacking above most components |
--vd-tooltip-dock-bg | color-mix(in srgb, #12141a 78%, transparent) | Dock variant background (flips to a frosted white in light schemes) |
--vd-tooltip-dock-color | #f4f4f5 | Dock variant text color |
--vd-tooltip-dock-border | color-mix(in srgb, #fff 22%, transparent) | Dock variant border |
--vd-tooltip-dock-shadow | drop + inset highlight | Dock 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
| Class | Description |
|---|---|
.vd-tooltip | Base 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-light | Light gray background with dark text. |
.vd-tooltip-dark | Dark background with white text. |
.vd-tooltip-glass | Frosted glass background with blur and translucent border. |
.vd-tooltip-dock | Denser 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-sm | Compact padding and smaller font. |
.vd-tooltip-lg | More spacious padding and larger font. |
.vd-tooltip-html | Allows HTML content inside the tooltip body. |
.vd-tooltip-wrapper | Optional inline-block wrapper for positioning context. |
Data Attributes
| Attribute | Description |
|---|---|
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
| Symbol | Description |
|---|---|
useTooltips(root, options?) | Composable — wires every [data-tooltip] / [data-tooltip-html] element inside the root ref. Call once in setup(). |
options.showDelay | Hover dwell in ms before a tooltip appears. Default 0 (immediate). Any trigger can override it with data-tooltip-delay. |
VdTooltip | SFC 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. |
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-labelon the trigger. - For keyboard users, tooltips should appear on
focusand hide onblur, not just on hover. - Use
aria-describedbyon 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-widthwith 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).