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.
tsimport {useTooltip} from '@astryxdesign/core/Tooltip'
Best practices
| Guidance | Practices |
|---|---|
| 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
| Param | Type | Description |
|---|---|---|
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
| Field | Type | Description |
|---|---|---|
| ref | RefCallback<HTMLElement> | Combined ref that sets both position and interaction on the same trigger element. |
| positionRef | RefCallback<HTMLElement> | Ref for the positioning anchor element. |
| interactionRef | RefCallback<HTMLElement> | Ref for the hover/focus interaction element. |
| anchorId | string | CSS anchor name for advanced positioning cases. |
| describedBy | string | 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. |