Components/Tooltip

Tooltip

A short hint shown on hover or focus.

VerifiedSince 0.3.4

Usage

EXAMPLE.VUE
<template>
  <TxTooltip content="Copied">
    <TxButton variant="ghost">Copy</TxButton>
  </TxTooltip>
</template>

Hover Hint

trigger defaults to hover; keyboard focus on the reference opens it too.

Loading demo...

Icon Button

Loading demo...

Anchor Config

anchor passes through to BaseAnchor and overrides defaults such as background, placement, and the arrow.

Loading demo...

Click Toggle

With trigger="click", a reference click toggles it and an outside click closes it.

Loading demo...

Keep Open on Outside Click

With closeOnClickOutside set to false, only another reference click or Escape closes it.

Loading demo...

Dashboard Feedback Center

A tooltip explains one action or metric; show lasting results with TxToastHost and block a refreshing panel with TxLoadingOverlay.

Loading demo...

Best Practices

  • Keep the text to one line.
  • Configure looks, placement, and motion through anchor.
  • Don't put forms, long explanations, or bulk actions in a tooltip; move complex content to TxPopover or TxDrawer.

API Reference

Props

PropTypeDefaultDescription
modelValuebooleanundefinedWhether it is open (v-model); omit it for uncontrolled use.
contentstring''Hint text; unused when the content slot is provided.
disabledbooleanfalseBlocks opening and closes the tooltip when it becomes disabled.
trigger'hover' | 'click' | 'focus' | 'manual''hover'How it opens; manual binds no reference interaction, so modelValue alone decides.
openDelaynumberFrom the layer preset (200 for hint)Open delay in ms for hover or focus; the shared delay service supplies it when unset.
closeDelaynumberFrom the layer preset (120 for hint)Close delay in ms for hover or focus; the shared delay service supplies it when unset.
maxHeightnumber320Panel max height in px; <= 0 removes it, as does using the content slot with it unset.
referenceFullWidthbooleanfalseStretches the reference wrapper to full width.
interactivebooleanfalseIn hover mode, lets the pointer move into the panel without closing it.
keepAliveContentbooleanfalseKeeps panel content mounted after close.
closeOnClickOutsidebooleantrigger === 'click'Closes on an outside click; takes precedence over the same key in anchor.
toggleOnReferenceClickbooleantrigger === 'click'Toggles on reference click; takes precedence over the same key in anchor.
layer'hint' | 'menu' | 'dialog''hint'Semantic overlay layer; picks the delay preset, exclusion rules, and default animation.
rolestring'tooltip'Panel ARIA role; any value but tooltip also drops the reference's aria-describedby.
unstyledbooleanfalseRenders the content bare, without tooltip typography or the height cap.
anchorPartial<TooltipAnchorProps>{}Passed to TxBaseAnchor, overriding the tooltip's placement, panel, and animation defaults; excludes modelValue and disabled.

Events

EventPayloadDescription
update:modelValue(value: boolean) => voidFires when the open state changes.
open() => voidFires after the tooltip opens.
close() => voidFires after the tooltip closes.

Slots

SlotPropsDescription
default-Reference content, wrapped in the trigger span.
content{ side: string }Custom tooltip body; side is the final side.

Exposed Methods

NameTypeDescription
updatePosition() => voidRecomputes the panel position.

Overview

  • With modelValue it is controlled; otherwise it keeps its own open state.
  • Hover and focus open and close on openDelay / closeDelay; with click, BaseAnchor handles toggling and outside clicks.
  • With interactive, the hover zone is the whole floating layer: the panel box, padding included, plus the hover bridge to the reference. The close is scheduled only on leaving all of it.
  • Also only with interactive: once the pointer leaves the reference toward the panel, it stays open while the pointer keeps moving inside the safe triangle. Parents stay open and hover triggers on the way do not open. A 100ms stop or a step outside closes it on closeDelay, and a trigger stopped on takes over.
  • The panel body carries role="tooltip" and data-side.
  • The default animation is { type: 'boom' }, which anchor.animation replaces entirely. No arrow is drawn by default; with one, the gap is still offset (8px by default).

Technologies

  • The safe triangle lives in packages/tuffex/packages/utils/hover-intent.ts, which listens to pointermove only during a trip; the anchor-delay service holds parent panels' deferred closes.
  • Source: packages/tuffex/packages/components/src/tooltip/.
查看源码
packages/tuffex/packages/components/src/tooltip/index.ts