useTooltip@astryxdesign/core v0.5.2 · useTooltip

Usage

Headless hook for hover/focus-triggered tooltips. Builds on useLayer with hover intent, keyboard focus handling, and accessible aria-describedby linking. Use for custom trigger elements that need tooltip behavior without the wrapper component.

ts
import {useTooltip} from '@astryxdesign/core/Tooltip'

Best practices

GuidancePractices
Do

Use for brief text labels that describe icon buttons, truncated text, abbreviations, or compact controls.

Do

Prefer the Tooltip component for standard wrapping; use the hook when the trigger is not a simple child.

Don't

Put interactive content inside tooltips: use Popover or HoverCard instead.

Parameters

ParamTypeDescription
placement
'above' | 'below' | 'start' | 'end' (default: 'above')

Position relative to the trigger. Logical: start/end resolve against the popover's own inherited direction (RTL mirrors in pure CSS).

alignment
'start' | 'center' | 'end' (default: 'center')

Alignment along the placement axis. Logical: start/end resolve against the popover's own inherited direction (RTL mirrors in pure CSS).

delay
number (default: 200)

Delay before showing on hover, in milliseconds.

hideDelay
number (default: 0)

Delay before hiding after mouse or focus leaves, in milliseconds.

focusTrigger
'auto' | 'always' | 'never' (default: 'auto')

When focus should open the tooltip. auto only attaches focus listeners to naturally focusable elements.

touchTrigger
'auto' | 'tap' | 'none' (default: 'auto')

What a tap does where there is no hover. auto opens on tap unless the trigger performs an action of its own; tap always opens (an info icon rendered as a button); none never opens on touch.

isEnabled
boolean (default: true)

Whether hover and focus triggers are enabled.

isOpen
boolean

Controlled open state. true force-shows, false force-hides, undefined lets hover/focus manage visibility.

isDefaultOpen
boolean (default: false)

Whether the tooltip should be shown on mount.

onShow
() => void

Callback fired when the tooltip becomes visible.

onHide
() => void

Callback fired when the tooltip is hidden.

Returns

FieldTypeDescription
refRefCallback<HTMLElement>

Combined ref that sets both position and interaction on the same trigger element.

positionRefRefCallback<HTMLElement>

Ref for the positioning anchor element.

interactionRefRefCallback<HTMLElement>

Ref for the hover/focus interaction element.

anchorIdstring

CSS anchor name for advanced positioning cases.

describedBystring

ID to compose into aria-describedby on the trigger.

renderTooltip(children: ReactNode, props?: Omit<ContextRenderProps, 'positioning'>) => ReactNode

Render function for the anchor-positioned tooltip content. The positioning opt-out is excluded: the tooltip always derives its position from placement/alignment.

Examples

Common configurations, variations, and states.
Tooltip — Hook Usage
Open in Playground

Tooltip using the useTooltip hook for programmatic control.