Tooltip
Displays a short explanation beside an element on hover or focus. Use it for icon buttons, truncated text and other read-only information that requires no clicks. To include buttons or links in the popup, use Popover.
Import
import { HuiTooltip } from '@nscode/handy-ui'
Basic Usage
Place the element in the default slot. content supplies the tooltip text.
<script setup lang="ts">
import { HuiTooltip, HuiButton } from '@nscode/handy-ui'
</script>
<template>
<HuiTooltip content="Save current changes">
<HuiButton>Save</HuiButton>
</HuiTooltip>
</template>
Common Usage
Esc closes only the topmost tooltip. Open the modal below, then hover over or focus its tooltip trigger. The first Esc keeps the modal open; the second closes the modal. A controlled tooltip must accept update:visible.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiModal, HuiTooltip, HuiSpace } from '@nscode/handy-ui'
const visible = ref(false)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiButton @click="visible = true">Open modal</HuiButton>
<HuiModal v-model:visible="visible" title="Esc handling order">
<p>Hover over or focus the button below, then press Esc twice.</p>
<HuiTooltip content="The first Esc hides only this tooltip, preserving focus and the modal">
<HuiButton>Tooltip trigger</HuiButton>
</HuiTooltip>
</HuiModal>
</HuiSpace>
</template>
Tooltips can explain icon-only buttons and truncated text.
<template>
<HuiSpace wrap align="center">
<HuiTooltip content="Edit">
<HuiButton icon="edit" aria-label="Edit" />
</HuiTooltip>
<HuiTooltip content="Share">
<HuiButton icon="share" aria-label="Share" />
</HuiTooltip>
<HuiTooltip content="Delete">
<HuiButton type="danger" icon="trash" aria-label="Delete" />
</HuiTooltip>
<HuiTooltip content="East China Sales Summary Q3 2026 (Including Returns).xlsx">
<span class="ellipsis">East China Sales Summary Q3 2026 (Including Returns).xlsx</span>
</HuiTooltip>
</HuiSpace>
</template>
<style scoped>
.ellipsis {
display: inline-block;
max-width: 160px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
vertical-align: middle;
}
</style>
Effect
effect has two values:
dark(default): contrasts with the page background. It uses a dark background with light text in a light theme, and a light background with dark text in a dark theme.light: uses the page background color, white in a light theme, with a border.
<template>
<HuiSpace wrap>
<HuiTooltip content="Dark tooltip" effect="dark">
<HuiButton>Dark (dark)</HuiButton>
</HuiTooltip>
<HuiTooltip content="Light tooltip" effect="light">
<HuiButton>Light (light)</HuiButton>
</HuiTooltip>
</HuiSpace>
</template>
Placement
placement accepts 12 values: top, bottom, left and right, each optionally followed by -start or -end to align with an edge. Top and bottom placements align with the left or right edge; left and right placements align with the top or bottom edge. The default is top.
When the chosen side lacks space, the tooltip flips to the opposite side. If it crosses the horizontal or vertical viewport edges, it shifts back inside while its arrow continues pointing to the trigger. Hover over the buttons below to compare. The switch changes the effect:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiRadio, HuiRadioGroup, HuiSpace, HuiTooltip } from '@nscode/handy-ui'
import type { TooltipEffect } from '@nscode/handy-ui'
const effect = ref<TooltipEffect>('dark')
</script>
<template>
<div class="placements">
<div class="placements__row placements__row--center">
<HuiRadioGroup v-model="effect" type="button" size="small">
<HuiRadio value="dark" label="dark" />
<HuiRadio value="light" label="light" />
</HuiRadioGroup>
</div>
<div class="placements__row placements__row--center">
<HuiTooltip :effect="effect" placement="top-start" content="top-start">
<HuiButton>top-start</HuiButton>
</HuiTooltip>
<HuiTooltip :effect="effect" placement="top" content="top">
<HuiButton>top</HuiButton>
</HuiTooltip>
<HuiTooltip :effect="effect" placement="top-end" content="top-end">
<HuiButton>top-end</HuiButton>
</HuiTooltip>
</div>
<div class="placements__row placements__row--between">
<HuiSpace direction="vertical" align="start">
<HuiTooltip :effect="effect" placement="left-start" content="left-start">
<HuiButton>left-start</HuiButton>
</HuiTooltip>
<HuiTooltip :effect="effect" placement="left" content="left">
<HuiButton>left</HuiButton>
</HuiTooltip>
<HuiTooltip :effect="effect" placement="left-end" content="left-end">
<HuiButton>left-end</HuiButton>
</HuiTooltip>
</HuiSpace>
<HuiSpace direction="vertical" align="end">
<HuiTooltip :effect="effect" placement="right-start" content="right-start">
<HuiButton>right-start</HuiButton>
</HuiTooltip>
<HuiTooltip :effect="effect" placement="right" content="right">
<HuiButton>right</HuiButton>
</HuiTooltip>
<HuiTooltip :effect="effect" placement="right-end" content="right-end">
<HuiButton>right-end</HuiButton>
</HuiTooltip>
</HuiSpace>
</div>
<div class="placements__row placements__row--center">
<HuiTooltip :effect="effect" placement="bottom-start" content="bottom-start">
<HuiButton>bottom-start</HuiButton>
</HuiTooltip>
<HuiTooltip :effect="effect" placement="bottom" content="bottom">
<HuiButton>bottom</HuiButton>
</HuiTooltip>
<HuiTooltip :effect="effect" placement="bottom-end" content="bottom-end">
<HuiButton>bottom-end</HuiButton>
</HuiTooltip>
</div>
</div>
</template>
<style scoped>
.placements {
max-width: 520px;
margin: 0 auto;
}
.placements__row {
display: flex;
gap: var(--hui-spacing-2);
}
.placements__row--center {
justify-content: center;
}
.placements__row--center + .placements__row--center {
margin-top: var(--hui-spacing-6);
}
.placements__row--between {
justify-content: space-between;
margin: var(--hui-spacing-3) 0;
}
</style>
Triggers
Tooltip has no trigger prop. Hover and focus are always supported:
- Hover: entering shows the tooltip.
enterabledefaults totrue, so entering the tooltip keeps it open. Without an explicithideAfter, leaving hides it after 100ms, allowing users to copy text. - Focus: focusing the trigger, or a button or input inside it, shows the tooltip. Losing focus hides it. Keyboard users can see it by pressing Tab.
- Manual control: pass only
:visiblewithout acceptingupdate:visible. Mouse and focus requests then have no effect on the actual state, which is determined entirely by the parent variable. The two adjacent buttons below change that variable.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiInput, HuiSpace, HuiTooltip } from '@nscode/handy-ui'
const keyword = ref('')
const visible = ref(false)
</script>
<template>
<HuiSpace wrap>
<HuiTooltip content="Shows on mouse entry and hides on mouse exit">
<HuiButton>Hover</HuiButton>
</HuiTooltip>
<HuiTooltip content="Shows when the input gains focus and hides when it loses focus">
<HuiInput v-model="keyword" placeholder="Focus" style="width: 160px" />
</HuiTooltip>
<HuiTooltip :visible="visible" content="Controlled only by the adjacent buttons">
<HuiButton>Manual (:visible only)</HuiButton>
</HuiTooltip>
<HuiButton type="primary" variant="link" @click="visible = true">Open</HuiButton>
<HuiButton type="primary" variant="link" @click="visible = false">Close</HuiButton>
</HuiSpace>
</template>
Offset
offset sets the gap between the tooltip and its trigger in pixels. The default is 8.
<template>
<HuiSpace wrap>
<HuiTooltip content="4px from the button" :offset="4">
<HuiButton>Offset 4</HuiButton>
</HuiTooltip>
<HuiTooltip content="8px from the button">
<HuiButton>Offset 8 (default)</HuiButton>
</HuiTooltip>
<HuiTooltip content="24px from the button" :offset="24">
<HuiButton>Offset 24</HuiButton>
</HuiTooltip>
</HuiSpace>
</template>
Custom Content
Use the content slot for content beyond a single line. The tooltip has a maximum width of 300px and wraps longer content.
<template>
<HuiSpace wrap>
<HuiTooltip effect="light">
<HuiButton>Keyboard shortcuts</HuiButton>
<template #content>
<div>Save: Ctrl + S</div>
<div>Undo: Ctrl + Z</div>
</template>
</HuiTooltip>
<HuiTooltip
content="This is a longer explanation. The tooltip has a maximum width of 300px and wraps instead of extending beyond the right edge of the screen."
>
<HuiButton>Long text wraps</HuiButton>
</HuiTooltip>
</HuiSpace>
</template>
Show and Hide Delays
showAfter delays showing after mouse entry; hideAfter delays hiding after mouse exit, both in milliseconds. Leaving or returning before the delay elapses cancels the pending show or hide. These delays apply only to mouse interactions. Focus and blur show or hide immediately.
<template>
<HuiSpace wrap>
<HuiTooltip content="Shows 500ms after mouse entry" :show-after="500">
<HuiButton>Delayed showing</HuiButton>
</HuiTooltip>
<HuiTooltip content="Hides 1 second after mouse exit" :hide-after="1000">
<HuiButton>Delayed hiding</HuiButton>
</HuiTooltip>
<HuiTooltip
content="Shows 300ms after mouse entry and hides 800ms after mouse exit"
:show-after="300"
:hide-after="800"
>
<HuiButton>Both delayed</HuiButton>
</HuiTooltip>
</HuiSpace>
</template>
Disabled
Set disabled to true to prevent showing. Disabling an open tooltip closes it immediately.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiTooltip, HuiButton, HuiCheckbox, HuiSpace } from '@nscode/handy-ui'
const disabled = ref(false)
</script>
<template>
<HuiSpace wrap>
<HuiTooltip content="Shows only when enabled" :disabled="disabled">
<HuiButton>Hover here</HuiButton>
</HuiTooltip>
<HuiCheckbox v-model="disabled">Disable tooltip</HuiCheckbox>
</HuiSpace>
</template>
Controlled Visibility
With v-model:visible, mouse entry and exit update the bound variable, and external changes can also show or hide the tooltip. With only :visible, without accepting update:visible, the parent fully controls visibility and mouse entry or exit does not change it. See manual control under Triggers.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiTooltip, HuiButton, HuiSpace } from '@nscode/handy-ui'
const visible = ref(false)
</script>
<template>
<HuiSpace wrap>
<HuiTooltip v-model:visible="visible" content="Controlled by hover and external buttons">
<HuiButton>Two-way binding</HuiButton>
</HuiTooltip>
<HuiButton @click="visible = !visible">Toggle</HuiButton>
<span>visible:{{ visible }}</span>
</HuiSpace>
</template>
Custom Transition
transition is the name of Vue's <Transition>. It defaults to hui-tooltip-fade, a fade-in/out animation. Define the corresponding -enter-active, -enter-from and other classes. Because the tooltip is attached under body, these styles must be global, without scoped.
<template>
<HuiTooltip content="Appears with a zoom animation" transition="my-zoom">
<HuiButton>Zoom animation</HuiButton>
</HuiTooltip>
</template>
<style>
.my-zoom-enter-active,
.my-zoom-leave-active {
transition:
opacity 0.3s ease,
transform 0.3s ease;
}
.my-zoom-enter-from,
.my-zoom-leave-to {
opacity: 0;
transform: scale(0.6);
}
</style>
Enterable Content and Immediate Hiding
By default, users can enter the tooltip to select and copy its text. With enterable=false and no explicit hideAfter, leaving the trigger hides it immediately.
<script setup lang="ts">
import { HuiTooltip, HuiButton, HuiSpace } from '@nscode/handy-ui'
</script>
<template>
<HuiSpace
><HuiTooltip content="Enter the tooltip to select and copy this text"
><HuiButton>enterable=true</HuiButton></HuiTooltip
><HuiTooltip :enterable="false" content="Hides immediately on leaving the trigger"
><HuiButton>enterable=false</HuiButton></HuiTooltip
></HuiSpace
>
</template>
Internal and Controlled Visibility
Without a visible prop, or with only an update listener, the component keeps its own visibility and starts hidden. Providing the prop makes it controlled; an explicit undefined means hidden. Both modes emit visibility requests through update:visible. If the parent rejects a request, the tooltip and its ARIA description still reflect the actual state. Changing control modes clears pending show/hide timers and produces a development diagnostic. Removing the prop restores internal state. Parent redraws do not reset it, while an actual loss of focus still hides the tooltip through the normal interaction.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiTooltip, HuiSpace } from '@nscode/handy-ui'
const tooltipBound = ref(false)
const tooltipRedraw = ref(0)
const tooltipLast = ref<boolean | string>('None yet')
const recordTooltip = (value: boolean) => {
tooltipLast.value = value
}
</script>
<template>
<HuiSpace class="tooltip-q1-demo" direction="vertical" fill>
<HuiButton class="tooltip-redraw" @click="tooltipRedraw++"
>Parent redraw {{ tooltipRedraw }}</HuiButton
>
<span
>Hover over the buttons or focus them with Tab; explicit undefined and fixed hidden values
retain the parent's state.</span
>
<HuiSpace wrap>
<HuiSpace class="tooltip-local" direction="vertical">
<span>Visibility prop omitted</span>
<HuiTooltip
:data-parent="tooltipRedraw"
content="Actual state determines the tooltip and its description reference"
:hide-after="0"
>
<HuiButton class="tooltip-trigger">Tooltip trigger</HuiButton>
</HuiTooltip>
</HuiSpace>
<HuiSpace class="tooltip-listener" direction="vertical">
<span>Update listener only</span>
<HuiTooltip
@update:visible="recordTooltip"
:data-parent="tooltipRedraw"
content="Actual state determines the tooltip and its description reference"
:hide-after="0"
>
<HuiButton class="tooltip-trigger">Tooltip trigger</HuiButton>
</HuiTooltip>
</HuiSpace>
<HuiSpace class="tooltip-empty" direction="vertical">
<span>Explicit undefined</span>
<HuiTooltip
:visible="undefined"
:data-parent="tooltipRedraw"
content="Actual state determines the tooltip and its description reference"
:hide-after="0"
>
<HuiButton class="tooltip-trigger">Tooltip trigger</HuiButton>
</HuiTooltip>
</HuiSpace>
<HuiSpace class="tooltip-fixed" direction="vertical">
<span>Always hidden; parent rejects opening</span>
<HuiTooltip
:visible="false"
:data-parent="tooltipRedraw"
content="Actual state determines the tooltip and its description reference"
:hide-after="0"
>
<HuiButton class="tooltip-trigger">Tooltip trigger</HuiButton>
</HuiTooltip>
</HuiSpace>
<HuiSpace class="tooltip-bound" direction="vertical">
<span>Two-way binding</span>
<HuiTooltip
v-model:visible="tooltipBound"
:data-parent="tooltipRedraw"
content="Actual state determines the tooltip and its description reference"
:hide-after="0"
>
<HuiButton class="tooltip-trigger">Tooltip trigger</HuiButton>
</HuiTooltip>
</HuiSpace>
</HuiSpace>
<span class="tooltip-status"
>Observed request: {{ tooltipLast }}; bound visibility: {{ tooltipBound }}</span
>
</HuiSpace>
</template>
Following the Pointer
With followCursor, placement is calculated relative to the pointer. Movement is batched by animation frame, using the last coordinates in that frame. The tooltip has no arrow and does not receive pointer events. enterable is ignored in this mode, and an omitted hideAfter hides it immediately on mouse exit. An explicit hiding delay keeps the last position until it closes.
Tab focus positions the tooltip beside its actual trigger and keeps its screen-reader description. A later pointer movement can resume following. Opening programmatically before any pointer position is known also uses the trigger. Hiding, changing the trigger or control mode, disabling, and unmounting cancel old animation frames. Replacing the trigger also invalidates old delays.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTooltip } from '@nscode/handy-ui'
import type { TooltipPlacement } from '@nscode/handy-ui'
const follow = ref(true)
const visible = ref(false)
const disabled = ref(false)
const customOffset = ref(false)
const light = ref(false)
const placement = ref<TooltipPlacement>('bottom')
const placements: TooltipPlacement[] = ['top', 'bottom', 'left', 'right']
const clicks = ref(0)
</script>
<template>
<HuiSpace class="tooltip-follow-demo" direction="vertical" fill>
<HuiSpace wrap>
<HuiButton @click="follow = !follow">Following: {{ follow }}</HuiButton>
<HuiButton @click="customOffset = !customOffset">{{
customOffset ? 'Offset: 24px' : 'Default offset'
}}</HuiButton>
<HuiButton @click="light = !light">{{ light ? 'Light' : 'Dark' }}</HuiButton>
<HuiButton @click="disabled = !disabled">Disabled: {{ disabled }}</HuiButton>
<HuiButton
v-for="value in placements"
:key="value"
:type="placement === value ? 'primary' : 'default'"
@click="placement = value"
>{{ value }}</HuiButton
>
</HuiSpace>
<HuiTooltip
v-model:visible="visible"
:follow-cursor="follow"
:disabled="disabled"
:offset="customOffset ? 24 : undefined"
:placement="placement"
:effect="light ? 'light' : 'dark'"
content="Follows the pointer; Tab focus uses the trigger position."
>
<button type="button" class="tooltip-follow-target" @click="clicks++">
Pointer and keyboard focus target
</button>
</HuiTooltip>
<p role="status">Visible: {{ visible }}; following: {{ follow }}; clicks: {{ clicks }}</p>
</HuiSpace>
</template>
<style scoped>
.tooltip-follow-target {
width: 100%;
min-height: 120px;
padding: var(--hui-spacing-4);
font: inherit;
color: var(--hui-text-color);
background: var(--hui-bg-color);
border: var(--hui-border-width) dashed var(--hui-border-color);
border-radius: var(--hui-border-radius);
cursor: default;
}
</style>
Props
The ordinary-mode defaults below apply when followCursor is off. With following enabled, an omitted offset uses 12px and an omitted hideAfter uses 0ms; explicitly supplied values, including 0, take precedence. enterable has no effect while following.
| Prop | Type | Default | Description |
|---|---|---|---|
| content | string | - | Tooltip text. Can also be provided through the content slot. The tooltip is hidden when neither is provided |
| placement | TooltipPlacement | 'top' | Position; see Types for all 12 values. Automatically flips when space is insufficient |
| disabled | boolean | false | Whether to disable the tooltip |
| offset | number | 8 | Gap between the tooltip and its trigger in pixels |
| transition | string | 'hui-tooltip-fade' | Transition name, passed to <Transition> |
| visible | boolean | — | Controlled when provided, including undefined as hidden. Otherwise keeps internal state, even with an update listener. Supports v-model:visible |
| showAfter | number | 0 | Delay in milliseconds after mouse entry. Focus shows immediately |
| hideAfter | number | undefined | Mouse-exit delay. When omitted with enterable=true, uses 100ms. Explicit 0 hides immediately. Blur hides immediately |
| effect | 'dark' | 'light' | 'dark' | dark contrasts with the page background; light uses a light background and border |
| enterable | boolean | true | Keeps the tooltip visible on mouse entry. Without hideAfter, leaving hides it after 100ms |
| followCursor | boolean | false | Positions against the pointer without an arrow or pointer interaction. Keyboard focus still uses the actual trigger |
Events
| Event | Callback Arguments | Description |
|---|---|---|
| update:visible | (value: boolean) | Reports visibility requests from mouse, focus or Esc in both modes. Repeated requests for the same actual state do not emit duplicate notifications |
Slots
| Slot | Scope Arguments | Description |
|---|---|---|
| default | - | Tooltip trigger element |
| content | - | Tooltip content, replacing the content prop |
Types
import type { TooltipPlacement, TooltipEffect, TooltipProps } from '@nscode/handy-ui'
type TooltipPlacement =
| 'top'
| 'top-start'
| 'top-end'
| 'bottom'
| 'bottom-start'
| 'bottom-end'
| 'left'
| 'left-start'
| 'left-end'
| 'right'
| 'right-start'
| 'right-end'
type TooltipEffect = 'dark' | 'light'
Trigger Nodes and Input Groups
With a single usable element or a component that forwards attributes, events and screen-reader associations attach directly to that node. Buttons retain joined borders in input groups and button groups, and an extra wrapper no longer constrains percentage-width inputs or flex layouts. Text, multiple nodes and disabled or loading buttons use a span to receive mouse events.
<script setup lang="ts">
import { ref } from 'vue'
import {
HuiButton,
HuiButtonGroup,
HuiInput,
HuiInputGroup,
HuiSpace,
HuiTooltip
} from '@nscode/handy-ui'
const value = ref('Search text')
const count = ref(0)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiInputGroup block>
<HuiInput v-model="value" placeholder="Search" />
<HuiTooltip content="Submit the current search"
><HuiButton @click="count++">Search</HuiButton></HuiTooltip
>
</HuiInputGroup>
<HuiButtonGroup>
<HuiTooltip content="Preserve user events"
><HuiButton @click="count++">Clicked {{ count }} times</HuiButton></HuiTooltip
>
<HuiTooltip content="This action is currently unavailable"
><HuiButton disabled>Disabled button</HuiButton></HuiTooltip
>
</HuiButtonGroup>
<p id="extra-hint">The user's own description is preserved.</p>
<HuiTooltip content="Additional tooltip"
><button aria-describedby="extra-hint">Focus to check both descriptions</button></HuiTooltip
>
</HuiSpace>
</template>