EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
Tooltip·hook·@astryxdesign/core

useTooltip

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.

Open in Playground @astryxdesign/core/Tooltip

Signature

Call shape
useTooltip(options: TooltipOptions = {}): TooltipReturn
Parameters
NameType and behavior
placement'above' | 'below' | 'start' | 'end' · optional · 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' · optional · default 'center'
Alignment along the placement axis. Logical: start/end resolve against the popover's own inherited direction (RTL mirrors in pure CSS).
delaynumber · optional · default 200
Delay before showing on hover, in milliseconds.
hideDelaynumber · optional · default 0
Delay before hiding after mouse or focus leaves, in milliseconds.
focusTrigger'auto' | 'always' | 'never' · optional · default 'auto'
When focus should open the tooltip. auto only attaches focus listeners to naturally focusable elements.
touchTrigger'auto' | 'tap' | 'none' · optional · 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.
isEnabledboolean · optional · default true
Whether hover and focus triggers are enabled.
isOpenboolean
Controlled open state. true force-shows, false force-hides, undefined lets hover/focus manage visibility.
isDefaultOpenboolean · optional · 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
NameType and behavior
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.

Showcases and examples

1 documented example

Tooltip — Hook Usage

Tooltip using the useTooltip hook for programmatic control.

Preview loads on approachPreview loads on approach
Exact source · tooltip-hook-usage
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {useTooltip} from '@astryxdesign/core/Tooltip';
import {Button} from '@astryxdesign/core/Button';
import {Center} from '@astryxdesign/core/Center';

export default function TooltipHookUsage() {
  const tooltip = useTooltip({
    placement: 'above',
    delay: 100,
  });

  return (
    <Center>
      <Button
        label="Using hook directly"
        ref={tooltip.ref}
        aria-describedby={tooltip.describedBy}
      />
      {tooltip.renderTooltip('Tooltip via hook')}
    </Center>
  );
}

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.

  • Use for brief text labels that describe icon buttons, truncated text, abbreviations, or compact controls.
  • Prefer the Tooltip component for standard wrapping; use the hook when the trigger is not a simple child.
  • Put interactive content inside tooltips: use Popover or HoverCard instead.