Tooltip

Tooltip

HkTooltip is the lightweight hint: a text bubble anchored to a trigger, shown after a short delay on hover or focus, and gone when the pointer or focus leaves. On the Vue side the same component also carries a second mode — trigger="click" — which turns the bubble into a small confirm surface with its own actions.

  • Reach for it for an annotation that describes a control: a glyph's meaning, a truncated value, a keyboard shortcut. It is text plus, in click mode, a decision — never a menu of choices; for a list use PopupSelect, for a panel with content use Popover.
  • The bubble cannot hold anything the user must click in hover mode, and it never blocks the pointer: the sheet arms pointer-events: none so a hint can never eat the click that summoned it. Click mode restores pointer events only while the bubble is visible.
  • It sits beside Popover rather than on top of it: both are popup-manager surfaces (the tooltip band), and neither is built from FloatingLayer. SelectPanel and PopupSelect do not render it; a tooltip on a select row is the host's own decision.

Import

tsx
1
import { HkTooltip } from "@celestia-island/hikari";
rust
1
2
3
4
5
use hikari_components::*;          // Tooltip, TooltipPlacement, TooltipTouchHintRequest, TOOLTIP_GAP_PX,
                                   // TOOLTIP_DEFAULT_DELAY_MS, TOOLTIP_TOUCH_SUPPRESS_MS,
                                   // tooltip_position_style, tooltip_position_declarations,
                                   // tooltip_pixel_snap_delta, next_tooltip_id
use hikari_components::prelude::*; // TooltipProps, rsx!, VNode, EventHandler

The Rust form is Tooltip(TooltipProps { … }); the trigger is the children: Element field and may be written directly as the component's children inside rsx!. Every prop may be omitted — text defaults to "" (Vue makes it optional too, String with default: ""), placement to top, delay to 300 ms.

Hover, focus, delay and the four sides

A tooltip engages on mouseenter and on focusin (focus events bubble, which is why the wrapper uses the in/out pair rather than focus/blur). After delay the bubble appears; leaving hides it and cancels a pending show. An empty text shows nothing at all — an empty bubble is worse than no bubble, and both runtimes guard on it.

Placement is one of four sides — top (the default), bottom, left, right — with an 8px gap (TOOLTIP_GAP_PX on the Rust side, the same TOOLTIP_GAP_PX in Vue's runtime/tooltipPosition.ts). The geometry is a pure function on both sides: tooltip_position_declarations(rect, placement, max_width) returns the five declarations in Vue's order — width: max-content, optional max-width, top, left, transform — and tooltip_position_style joins them into one inline string.

Both cards render the same DOM contract: span.hk-tooltip-wrapper[data-position] → span.hk-tooltip-trigger (the button) and div.hk-tooltip-popup.hk-tooltip-{placement}[role="tooltip"] → div.hk-tooltip-content. The difference is how the bubble becomes visible — and in this page's cards, that neither bubble is visible: a static preview cannot hover a trigger (see the note below).

The snapshot shows the hidden state (Rust, deliberately). Vue mounts the popup lazily on the first engage and toggles .hk-tooltip-visible; the Rust mirror renders the popup from the first paint and the sheet's own opacity: 0 keeps it invisible — the doc comment for the HkTooltip.scss rule says so. Nothing in either example opens a bubble, and a static preview cannot hover a trigger. The visible bubble is therefore not part of this page's examples; on the TSX card the same two buttons show it for real on hover or focus, after the delay.

[D] The visibility carrier differs by design. Vue toggles a class; the Rust mirror writes the popup's inline opacity (0 ↔ 1) — the exact declaration the .hk-tooltip-visible rule carries — because component-body hooks are render-scoped in tairitsu 0.5.22 and a visible flag living for one render would be reset by any parent re-render. The class stays in the sheet for the Vue form and for hosts that set it themselves.

[D] Lazy mount is not reproduced. Vue's popup exists only after the first engage (a dense tag list of never-hovered tooltips costs no teleported node, no band registration, no pointer wiring). The Rust mirror renders the popup from the first paint and never registers with a popup manager.

What the Rust mirror does not do

The Rust geometry is the minimal variant of Vue's placement pass. The anchor math is Vue's, but three things are missing, and they are missing on purpose rather than by accident:

  • the ancestorZoom(document.body) division (runtime/cssZoom.ts) — the factor is 1.0 in every root that carries no CSS zoom;
  • the measure-and-clamp pass of applyTooltipPosition (flip, cap, shrink, viewport-gutter clamp) — a bubble that would spill past the gutter is not flipped or shrunk, it keeps its anchor placement;
  • the afterLeave edge and any leave-transition driver, so there is no "finished leaving" event to report.

max_width still overrides the sheet's own 280px cap, and it is written in the same position Vue writes it (width first, then max-width).

The cap is the point of these two cards: the same long text wrapped at max-width: 120px instead of the sheet's 280px. On the Rust side the popup's inline style is width:max-content;max-width:120px from the first paint; on the TSX side it is written when the bubble engages. Neither card can show the wrapped box statically — hover the TSX trigger, or run the Rust example in a wasm build.

The keyboard model, for the host that has to mirror it: ArrowDown / ArrowUp and Enter belong to the trigger in normal use; the tooltip itself owns no keys, and Escape does nothing in hover mode. In click mode the Vue form closes on Escape and on a pointer press outside the trigger and the bubble, and hands focus back to the trigger.

What the Rust mirror cannot run: touch. Vue hands a touch or pen press to runtime/touchHint.ts (armTouchHint(wrapper, text, { pointerId, origin })): a long-press shows a top-docked hint bar, a quick tap shows nothing, and the press's synthetic mouse events are suppressed for 600 ms (TOOLTIP_TOUCH_SUPPRESS_MS). The mirror cannot run that recognizer — it needs document-level capture listeners, and tairitsu_vdom::DomOps is element-scoped. Instead the press leaves through on_touch_hint as a TooltipTouchHintRequest { text, pointer_id, client_x, client_y }, and the host arms its own long-press and mounts TouchHintBar. A host that wires nothing gets no touch hint: the tap does not fall back to the anchored bubble, which is exactly Vue's "a quick tap shows nothing".

Source defect (Rust). The popup id is allocated per render (next_tooltip_id() inside the component body), not once per instance as Vue does (popupSeq in setup). The doc comment acknowledges this ("re-allocated per render instead of once per instance") and keeps the measurement hook (data-hk-tooltip-anchor) in sync so a handler can never point at a stale element — but every re-render of a Rust tooltip rewrites the id on the wrapper, on aria-describedby and on the popup. Anything outside the component that captured the id (a test, a host's own describedby wiring) goes stale on the next parent re-render.

Source defect (Rust). aria-describedby is rendered statically on the wrapper, so every tooltip in the page — including the thousands in a dense list that never show — is a permanent description link. Vue links it only while its lazily mounted popup exists (visible), which is why a screen reader in Vue announces the hint only when it is actually up. On the Rust side the description is always attached; that is a deliberate trade (the popup node always exists, so the link is always valid) but it changes what assistive technology reads on focus.

API

Vue

Props

NameTypeDefaultRequired
textString""—
placementString as PropType<TooltipPlacement>"top"—
delayNumber300—
maxWidthStringundefined—
triggerString as PropType<TooltipTrigger>"hover"—
allowBandOverlapBooleanfalse—

Rust

Props — Tooltip

PropTypeDefaultDescription
textString""The hint text (hk-tooltip-content).
placementTooltipPlacementTooltipPlacement::TopWhich side of the trigger the bubble is anchored to.
delayu32TOOLTIP_DEFAULT_DELAY_MS (300)Milliseconds between the engage and the bubble (Vue default 300).
max_widthOption<String>NoneInline max-width override (Vue: maxWidth, default undefined — the sheet's own max-width: 280px then applies).
childrenElement(empty)The trigger (Vue: the default slot), rendered inside span.hk-tooltip-trigger.
classString""Extra class appended to the wrapper (Vue: attribute fallthrough).
on_touch_hintOption<EventHandler<TooltipTouchHintRequest>>NoneThe touch/pen handover (see the file header's touch delta).

Accessibility

  • The bubble is role="tooltip"; the wrapper is the anchor that describes it. In Vue the wrapper carries aria-describedby while the bubble is visible; the Rust mirror carries it permanently — see the source defect above before you rely on when a description is announced.
  • A hint is a supplement, never the only name. Put the real meaning in the trigger's own text or aria-label; if the tooltip disappears on blur, a keyboard user who never hovers gets nothing.
  • Hover mode takes no pointer events, so the bubble can never cover its trigger and cannot itself be hovered. Do not put links into hover tooltips — they are unreachable by design.
  • trigger="click" (Vue) is a different contract: the bubble becomes role="dialog" with aria-haspopup="dialog" and a live aria-expanded on the wrapper, takes focus on open (tabindex="-1"), closes on Escape (returning focus to the trigger) and on an outside pointer press, and marks the closed popup inert so its actions are neither tab stops nor announced. Use it for "are you sure?" shapes, and pass the question in text — it becomes the dialog's aria-labelledby title.
  • Touch: an anchored bubble under the finger hides the very element being inspected, which is why the ball is passed to the top-docked hint bar on both sides. Nothing is shown on a quick tap.
  • [D] The Rust mirror has no click mode, no inert, no dismissal wiring and no focus hand-back. A confirm surface on the Rust side is a Popover with its own on_open_change, not a Tooltip.

Related components

  • Popover — the interactive sibling: the same anchoring, a real panel, dismissal and focus.
  • IconButton — the usual trigger for a glyph hint.
  • PopupSelect — when the thing beside a control is a choice, not a description.
  • FloatingLayer — the other side of the same band: chrome that must outlive windows.