Tooltip is not a surface — it is the manager that shows short supplemental context next to an anchor element, positions it inside the visible bounds, animates it in and out, and tears it down. The surface it paints is TooltipContainer.InteractableBase — Button, Container, ListItem, and the rest — accepts tooltipText and a tooltipMode. This wires up focus, dismissal, and the single-tooltip-at-a-time rule for you.useTooltip. An imperative handle plus a portal node you render, for anchors that are not the toolkit controls or for tooltips driven by your own logic.Tooltip. A declarative wrapper over useTooltip that takes an anchorRef and an isVisible flag.import { Button, TooltipMode } from '@wearables-ui-toolkit/mrbd';
<Button
icon={captureIcon}
ariaLabel="Capture"
tooltipText="Capture"
tooltipMode={TooltipMode.DWELL}
onActivate={capture}
/>
<Button
title="Send"
disabled={!isConnected}
tooltipText="Reconnect to send"
tooltipMode={TooltipMode.DISABLED_CLICK}
onActivate={send}
/>
tooltip.portal from the component that owns the anchor. It is null while nothing is showing.import { useRef } from 'react';
import { useTooltip } from '@wearables-ui-toolkit/mrbd';
export function ZoomReadout({ zoomLabel }: { zoomLabel: string }) {
const anchorRef = useRef<HTMLDivElement>(null);
const tooltip = useTooltip();
return (
<div
ref={anchorRef}
tabIndex={0}
onFocus={() => {
const anchor = anchorRef.current;
if (anchor) {
tooltip.show(anchor, { text: 'Zoom', metadata: zoomLabel });
}
}}
onBlur={() => tooltip.hide()}
>
{zoomLabel}
{tooltip.portal}
</div>
);
}
update rather than show when only the content changes, so a live readout does not restart its entrance animation on every value:const anchor = anchorRef.current;
if (anchor) {
tooltip.update(anchor, { text: 'Zoom', metadata: zoomLabel });
}
anchorRef must reference a DOM element. The toolkit control refs are component handles, not elements, so anchor to an element you own — or use the tooltip props on the control, which is what they are for.import { useRef, useState } from 'react';
import { Tooltip, TooltipPosition } from '@wearables-ui-toolkit/mrbd';
export function ReorderHint({ children }: { children: React.ReactNode }) {
const anchorRef = useRef<HTMLDivElement>(null);
const [isHintVisible, setHintVisible] = useState(true);
return (
<div ref={anchorRef}>
{children}
<Tooltip
anchorRef={anchorRef}
text="Long-press to reorder"
isVisible={isHintVisible}
position={TooltipPosition.ANCHORED}
shouldAutoDismiss
onHide={() => setHintVisible(false)}
/>
</div>
);
}
TooltipProps. Tooltip renders nothing of its own; it drives useTooltip from props and returns that hook’s portal.| Prop | Type | Default | Description |
|---|---|---|---|
anchorRef | RefObject<HTMLElement \| null> | — | Required. The element the tooltip points at. Must be mounted while the tooltip is visible. |
text | string | — | Primary text. |
metadata | string | — | Secondary text shown after the primary text. |
icon | IconSource | — | Leading icon. |
trailingIcon | IconSource | — | Trailing icon. |
content | ReactNode | — | Custom content rendered instead of the built-in container. Suppresses text, metadata, and both icons. |
contentDescription | string | — | Accessible name. Falls back to text and metadata joined. |
isFocusable | boolean | false | Lets the overlay take pointer events. Required for interactive custom content. |
tracksAnchorScale | boolean | false | Follows an anchor that is being scaled or animated, re-measuring every frame. |
centerPositionProvider | TooltipCenterPositionProvider | — | Supplies the point the tooltip should point at, relative to the anchor. |
targetRectProvider | TooltipTargetRectProvider | — | Supplies the rectangle the tooltip should point at, relative to the anchor. |
isVisible | boolean | false | Shows or hides the tooltip. |
onHide | () => void | — | Called once when the tooltip stops being presented, at the start of its exit fade rather than at the end of it. |
position | TooltipPosition | TooltipPosition.ANCHORED | Preferred placement. |
shouldAutoDismiss | boolean | false | Hides the tooltip on its own 5000 ms after it is shown. |
showTooltipTail | boolean | true | Draws the pointer tail on the built-in container. |
InteractableBase| Prop | Type | Default | Description |
|---|---|---|---|
tooltipText | string | — | Primary text. Nothing shows without this or tooltipContent. |
tooltipMetadata | string | — | Secondary text. |
tooltipContent | ReactNode | — | Custom content instead of the built-in container. |
tooltipContentDescription | string | — | Accessible name for the tooltip. |
tooltipMode | TooltipMode | TooltipMode.NONE | When the tooltip appears. |
tooltipPosition | TooltipPosition | TooltipPosition.ANCHORED | Preferred placement. |
tooltipShowTail | boolean | true | Draws the pointer tail. |
tooltipFocusable | boolean | false | Lets the tooltip take focus, for interactive custom content such as a menu. |
tooltipHidesFocusState | boolean | false | Suppresses the control’s focus visuals while its tooltip is up. |
tooltipCenterPositionProvider | TooltipCenterPositionProvider | — | Anchor-relative point to point at. |
tooltipTargetRectProvider | TooltipTargetRectProvider | — | Anchor-relative rectangle to point at. |
tooltipText and tooltipMetadata are the only built-in content it can draw. Use tooltipContent when you need an icon, and pass it a TooltipContainer so the surface still matches.useTooltip() returns a TooltipState.| Member | Type | Description |
|---|---|---|
isShowing | boolean | true while a tooltip is presented and not yet dismissing. |
portal | ReactNode | The portalled overlay. Render it; it is null when nothing is showing. |
show | (anchor: HTMLElement, options: TooltipShowOptions) => void | Presents a tooltip against anchor. Replaces any tooltip this hook is already showing and fires that one’s onHide first. Does nothing when the options carry no content. |
update | (anchor: HTMLElement, options: TooltipShowOptions) => void | Swaps the content of a tooltip already showing on the same anchor without restarting the presentation. Falls back to show for a different anchor or when nothing is showing, and hides when the content becomes empty. |
hide | (animated?: boolean) => void | Hides the tooltip. animated defaults to true, which fades out before firing onHide; false tears it down immediately. |
refreshPosition | () => void | Recomputes the position immediately, for anchor movement the manager cannot observe. |
TooltipPosition| Member | Value | Description |
|---|---|---|
ANCHORED | 'anchored' | Above the anchor. Tail points down. |
ANCHORED_BOTTOM | 'anchoredBottom' | Below the anchor. Tail points up. |
CENTERED | 'centered' | Horizontally centred within the tooltip bounds rather than on the anchor, and placed above it vertically. A control’s CENTERED tooltip draws no tail; through Tooltip or useTooltip the built-in surface still draws one, so pass showTooltipTail={false} alongside it. |
TooltipMode| Member | Value | Description |
|---|---|---|
NONE | 'none' | No tooltip. The default. |
FOCUSED | 'focused' | Shows while the control is focused or pressed. |
DWELL | 'dwell' | Shows once the control has been focused or pressed continuously for 3000 ms. |
DISABLED_CLICK | 'disabledClick' | Shows when a disabled control is activated, then hides itself 5000 ms later. |
ALWAYS | 'always' | Shown for as long as the control is mounted with tooltip content. |
TooltipShowOptionsshow and update take. It carries the same content, placement, and provider fields as the component props, plus onHide.| Field | Type | Default | Description |
|---|---|---|---|
text | string | — | Primary text. |
metadata | string | — | Secondary text. |
icon | IconSource | — | Leading icon. |
trailingIcon | IconSource | — | Trailing icon. |
content | ReactNode | — | Custom content instead of the built-in container. |
contentDescription | string | — | Accessible name. |
isFocusable | boolean | — | Lets the overlay take pointer events. |
tracksAnchorScale | boolean | — | Re-measures the anchor every frame. |
centerPositionProvider | TooltipCenterPositionProvider | — | Anchor-relative point to point at. |
targetRectProvider | TooltipTargetRectProvider | — | Anchor-relative rectangle to point at. |
shouldAutoDismiss | boolean | false | Hides the tooltip 5000 ms after it is shown. |
position | TooltipPosition | TooltipPosition.ANCHORED | Preferred placement. |
showTooltipTail | boolean | true | Draws the pointer tail on the built-in container. |
onHide | () => void | — | Fires exactly once when this presentation ends, whether it was hidden explicitly, replaced by another show, or auto-dismissed. |
TooltipStateuseTooltip() returns. Its members are listed under Imperative handle above: isShowing, portal, show, update, hide, and refreshPosition.| Type | Signature | Description |
|---|---|---|
TooltipCenterPositionProvider | (anchor: HTMLElement) => TooltipAnchorPoint \| null \| undefined | Returns the point the tooltip should aim at. |
TooltipTargetRectProvider | (anchor: HTMLElement) => TooltipAnchorRect \| null \| undefined | Returns the rectangle the tooltip should aim at. |
TooltipAnchorPoint is { x: number; y: number }. TooltipAnchorRect is { left, top, right, bottom } with optional width and height; when width is omitted it is derived from right - left.null to fall back to the anchor’s own box. When both providers are supplied, the rectangle wins for the vertical edges and the point wins for the horizontal centre.TooltipPresentationProvider for selecting the component used when a tooltip has text or metadata but no custom content:import {
TooltipPresentationProvider,
type DefaultTooltipPresentation,
} from '@wearables-ui-toolkit/foundation';
| Prop | Type | Description |
|---|---|---|
children | ReactNode | Subtree that uses the presentation. |
presentation | DefaultTooltipPresentation | Component that renders the default tooltip content. |
DefaultTooltipPresentation receives DefaultTooltipPresentationProps: text, metadata, showTooltipTail, tailDirection, and tailCenterX. The presentation owns its visual markup and must keep text and metadata available to assistive technology.App installs TooltipContainer for the whole toolkit tree. Prefer the content or tooltipContent prop for a one-off custom tooltip. Use a nested TooltipPresentationProvider only when a subtree needs a different default presentation for every tooltip.text, metadata, or content is set. Clearing them all while visible hides the tooltip.isVisible stays true, Tooltip applies new props through update, so changing the text of a tooltip that is already up swaps the content without restarting the entrance fade.CENTERED centres it in the bounds instead.ANCHORED sits above the anchor and ANCHORED_BOTTOM below it. A tooltip that renders the built-in container always keeps the side you asked for. Only custom content flips to the other side when the requested side cannot fit and the other side has more room — and on a control, only when that content is also focusable, which is the popup case such as a menu.App renders — and fall back to the viewport. The overlay is clipped to those bounds, so it never spills outside them. A control’s tooltip is additionally pulled back inside them both horizontally and vertically; through Tooltip or useTooltip only the horizontal position is pulled back, so a tooltip anchored too close to the top or bottom edge is trimmed rather than moved. Leave room for it, or ask for the other side.showTooltipTail={false} removes it, and a control’s CENTERED tooltip has none because it is not aligned to the anchor. Custom content given to Tooltip or useTooltip is rendered exactly as you wrote it and gets no tail; a control instead hands its resolved tail direction and horizontal offset to tooltipContent, which is how ContextMenu draws its own. The gap between tooltip and anchor is larger when there is no tail, so turning the tail off does not leave the surface sitting on the control.refreshPosition. A control’s tooltip additionally re-measures on every animation frame while it is visible, so it stays attached to a control that a CSS transform is moving inside a rail or carousel; a tooltip you drive yourself does not, which is what refreshPosition is for. tracksAnchorScale makes Tooltip and useTooltip measure the anchor’s scaled box every frame too; turn it on only while such an animation runs.hide(false) skips the fade entirely and tears the overlay down in the same tick.useTooltip likewise replaces the tooltip it is already showing, firing the replaced tooltip’s onHide first. The two paths do not coordinate with each other, and each useTooltip call site is its own presenter, so a hand-driven tooltip can sit on screen alongside a control’s. Drive at most one hand-managed tooltip per screen.shouldAutoDismiss for a hint that should disappear on its own.FOCUSED or DWELL tooltip hides when the control loses focus, except that a FOCUSED tooltip whose custom content is focusable stays up for as long as that content holds focus; a DISABLED_CLICK tooltip hides itself after its dismiss delay. A focusable tooltip from the interactable base — the menu case — also handles Escape and the browser back key: it forwards the key to the popup content, dismisses, returns focus to the anchor, and stops the key before route history sees it. A tooltip driven by useTooltip is yours to hide.isFocusable is set.App. See Floating portals.role="tooltip" and is named by contentDescription when you supply one, otherwise by text and metadata joined. With custom content, supply contentDescription yourself — there is no text to fall back to.useTooltip or Tooltip is also a polite live region, so it is announced when it appears.ariaLabel on an icon-only control is not optional just because a tooltip exists.FOCUSED or DWELL to name icon-only controls.DISABLED_CLICK to explain why a control is unavailable.metadata.update for a value that changes while the tooltip stays up.tooltipFocusable on the control when the tooltip hosts something interactive, such as a VerticalMenu — that path is the one that adds Escape and back dismissal and returns focus to the anchor. isFocusable on Tooltip and useTooltip only lets the overlay take pointer events; dismissal is still yours to drive there.tracksAnchorScale on outside an anchor animation — it re-measures every frame.ALWAYS on a control in a dense layout — it will cover its neighbours.