Delb includes a simple, reusable tooltip directive (v-tooltip) that you can attach to any element. The tooltip is rendered into document.body (so it won’t be clipped by scroll/overflow containers), and it will auto-flip / clamp to stay within the viewport.
<template>
<button v-tooltip="'Save changes'">
Save
</button>
</template>
<template>
<button
v-tooltip="{
text: 'Saves your changes',
side: 'right',
offset: 10,
viewportPadding: 12,
showDelay: 200,
hideDelay: 0
}"
>
Save
</button>
</template>
You can pass either:
- a
string(tooltip text), or - an object with the following fields:
- Type:
string - The tooltip content.
- Type:
"top" | "right" | "bottom" | "left" - Default:
"top" - Preferred placement side. If
autoFlipis enabled, the tooltip may render on a different side to avoid clipping.
- Type:
number - Default:
8 - Gap (in pixels) between the target element and the tooltip.
- Type:
number - Default:
8 - Minimum distance (in pixels) to keep from the viewport edges.
- Type:
number - Default:
150 - Delay (ms) before showing the tooltip on hover/focus.
- Type:
number - Default:
0 - Delay (ms) before hiding the tooltip on leave/blur.
- Type:
string(CSS value, e.g."240px","20rem") - Optional
- Sets a per-tooltip max width; otherwise defaults to the global CSS variable
--tooltip-max-width.
- Type:
boolean - Default:
true - When enabled, the tooltip will choose a side that best fits within the viewport.
- Type:
boolean - Default:
false - When enabled, the tooltip allows pointer interaction (sets
pointer-events: autoon the tooltip).
Note: the tooltip is non-interactive by default (pointer-events: none) to avoid interfering with hovering/clicking the target.
- Teleported to body: Tooltip DOM is appended to
document.body, which avoids clipping by containers withoverflow: hidden/auto/scroll. - Viewport safety: Tooltip coordinates are clamped to the viewport with
viewportPadding, and it canautoFlipwhen there isn’t enough room on the preferred side. - Keyboard accessibility: The directive shows tooltips on
focusand hides them onblur.- For non-focusable elements, the directive may add
tabindex="0"so keyboard users can reveal the tooltip. - The directive should not add
tabindexto elements that arearia-hidden="true"(common for decorative icon spans), because a focusedaria-hiddenelement triggers browser accessibility warnings and hides focus from assistive technology users.
- For non-focusable elements, the directive may add
- ARIA wiring:
- When the target is accessible, the directive uses
aria-describedbyto associate the tooltip content. - If the target is
aria-hidden="true"(or otherwise should not be described), the directive should avoidaria-describedbyand instead rely on an accessible wrapper element (e.g. a<button aria-label="...">...</button>) for the name/description.
- When the target is accessible, the directive uses
- Dismiss on outside click/tap: If a tooltip is open, pointer down outside the target (and outside the tooltip when
interactive: true) hides it.
Tooltips use global CSS under the .tooltip class, with CSS variables for customization (defined in the main stylesheet). The directive sets positioning via:
--tooltip-x--tooltip-y
You can adjust visuals by overriding variables such as:
--tooltip-bg--tooltip-fg--tooltip-shadow--tooltip-radius--tooltip-max-width--tooltip-z--tooltip-arrow-size