Tooltip
Shows a short text label or description for its child on hover and keyboard focus.
- The text is always present as a hidden role="tooltip" element referenced by the child's aria-describedby (or aria-labelledby with relationship="label"), so screen readers get it on focus without waiting for the delay; the child's own ids are kept.
- The visual surface is rendered in a portal while visible (it is aria-hidden, a copy of the description), positioned on side/align with flipping and shifting to stay in view.
- It fades in and out over 100 ms (see motion; at once under reduced motion). The surface mounts through the presence core: it carries data-presence and data-state="open", and while it fades out data-state="closed" and inert, staying where it was until its exit ends; the Escape layer goes as it hides, not after the fade. Shown again during its exit, the same surface fades back in. The hidden description is unchanged in every phase.
- It appears openDelay after the pointer rests on the child or the child takes keyboard focus, stays visible while the pointer moves onto it, hides closeDelay after the pointer leaves or immediately on blur, and Escape hides it without closing an enclosing dialog or popover. Focus and hover inside a popup the child renders in a portal (a DatePicker calendar, a listbox) do not show it, and the pointer moving onto such a popup hides it.
- The open state is uncontrolled by default (defaultOpen). With open and onOpenChange (Fluent's visible and onVisibleChange) the parent owns it: hover, focus, leave, blur and Escape then only ask for a change, and open alone shows the surface.
- id and aria-* props given to the Tooltip go to its child, merged with the child's own (the child's id wins, id lists are joined, aria-expanded/aria-controls/aria-haspopup from the Tooltip win). className, style, ref, data-* and event handlers stay on the wrapper <span>; the handlers see the child's events as they bubble, not events from portaled content such as the tooltip surface or a popup the child renders in a portal (a DatePicker calendar, a listbox). onMouseEnter and onMouseLeave are the exception: React fires them along the component tree, so they also fire when the pointer moves onto or off the tooltip surface or such a popup. So the Tooltip can sit inside a trigger, and the trigger's id and state reach the button: <Menu.Trigger><Tooltip content="โฆ"><Button /></Tooltip> </Menu.Trigger> (also Popover.Trigger, Dialog.Trigger, Drawer.Trigger). Around a trigger works too, since triggers pass aria-describedby on to their child.
- Wrap the focusable element itself. When the element that takes focus does not get the relationship (a Popover or Dialog root, a component that drops props, a non-focusable wrapper element), it is added to the first focusable element inside, with a development warning.
* - **No wrapper.** asChild renders no <span>: the handlers, ref and props merge onto the child, which must forward ref and spread its props, and the hidden description and the surface render next to it.
- **Relationship.** relationship="inaccessible" shows a purely visual hint: no aria-describedby or aria-labelledby on the child, and no hidden description.
- **Beak and anchor.** withArrow draws a beak; positioning.target places the surface at another element or a VirtualElement, and the surface hides while its anchor is scrolled out of view or clipped.
- **One at a time.** Showing a tooltip hides every other one; a tooltip hides when the document is hidden (another tab), when the child's popup is expanded (a Menu or Popover its trigger opened: aria-expanded="true" on the child or an element inside it) and stays hidden while it is. While it fades out it keeps the content it showed, so a text you reset in onOpenChange(false) (a "Copied" back to "Copy") does not change during the fade.
Examples
Default
export const Default: Story = {};Normal
export const Normal: Story = {
args: {
content: 'Normal tooltip',
appearance: 'normal',
children: <Button>Normal Tooltip</Button>,
},
};Icon Only Label
export const IconOnlyLabel: Story = {
args: {
content: 'Save',
relationship: 'label',
children: <Button icon={<SaveIcon />} />,
},
};Long Content
export const LongContent: Story = {
args: {
content:
'Tooltips wrap long text instead of running off the screen, and flip to the other side near the viewport edge.',
children: <Button>Long tooltip</Button>,
},
};Controlled
export const Controlled: Story = {
args: {
content: 'Pinned while the toggle is on',
children: <Button>Hover or focus me</Button>,
},
render: function ControlledTooltip(args) {
const [open, setOpen] = React.useState(false);
const [pinned, setPinned] = React.useState(false);
const handleOpenChange = (next: boolean) => {
args.onOpenChange?.(next);
if (!pinned) setOpen(next);
};
return (
<div className="flex items-center gap-4">
<ToggleButton pressed={pinned} onPressedChange={setPinned}>
Pin tooltip
</ToggleButton>
{/* The story owns the controlled pair; every other arg is forwarded. */}
<Tooltip {...args} open={pinned || open} onOpenChange={handleOpenChange} />
</div>
);
},
};Inside A Trigger
export const InsideATrigger: Story = {
args: {
content: 'Narrow the list',
children: <Button>Filters</Button>,
},
render: (args) => (
<Popover>
<Popover.Trigger>
<Tooltip {...args} />
</Popover.Trigger>
<Popover.Content title="Filters">Choose which items to show.</Popover.Content>
</Popover>
),
};Delays
export const Delays: Story = {
args: {
content: 'Appears at once and stays for a second',
openDelay: 0,
closeDelay: 1000,
children: <Button>Quick to show, slow to hide</Button>,
},
render: (args) => (
<div className="flex items-center gap-4">
<Tooltip {...args} />
<Tooltip {...args} content="Appears after a second" openDelay={1000} closeDelay={100}>
<Button>Slow to show</Button>
</Tooltip>
</div>
),
};Motion
export const Motion: Story = {
render: ({ children: _children, ...args }) => (
<div className="flex items-center gap-4">
{motionCases(fadeAndZoom).map(({ label, motion }) => (
// The story renders one tooltip per case; every other arg is forwarded.
<Tooltip key={label} {...args} motion={motion}>
<Button>{label}</Button>
</Tooltip>
))}
</div>
),
};Inaccessible And Arrow
export const InaccessibleAndArrow: Story = {
render: ({ children: _children, ...args }) => (
<div className="flex items-center gap-4">
<Tooltip {...args} relationship="inaccessible" content="Also named by its text">
<Button>Save</Button>
</Tooltip>
<Tooltip {...args} withArrow content="With a beak">
<Button>Arrow</Button>
</Tooltip>
</div>
),
};No Wrapper And Target
export const NoWrapperAndTarget: Story = {
render: function NoWrapperTooltips({ children: _children, ...args }) {
const [target, setTarget] = React.useState<HTMLElement | null>(null);
return (
<div className="flex items-center gap-4">
<Tooltip {...args} asChild content="No wrapper element">
<Button>No wrapper</Button>
</Tooltip>
<Tooltip {...args} positioning={{ target }} content="Placed at the box" side="bottom">
<Button>Points at the box</Button>
</Tooltip>
<div ref={setTarget} className="rounded-md border border-wave-border px-3 py-2">
The box
</div>
</div>
);
},
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
content | React.ReactNode | Yes | Content to display inside the tooltip (short, non-interactive text). | |
appearance | 'inverted' | 'normal' | No | 'inverted' | Color treatment: |
openDelay | number | No | 200 | Milliseconds before the tooltip appears when the pointer rests on the child or the child receives keyboard focus (Fluent's |
closeDelay | number | No | 100 | Milliseconds before it hides once the pointer has left the child and the tooltip (Fluent's |
open | boolean | No | Controlled open state (Fluent's | |
defaultOpen | boolean | No | false | Initial open state for uncontrolled usage. |
onOpenChange | (open: boolean) => void | No | Called with the new open state when it changes (Fluent's | |
relationship | 'description' | 'label' | 'inaccessible' | No | 'description' | How the tooltip relates to its child: |
withArrow | boolean | No | false | Draws a beak, the small triangle that points at the child (or |
asChild | boolean | No | false | Renders no wrapper element: the Tooltip's handlers (hover, focus and blur), its |
side | 'top' | 'bottom' | 'start' | 'end' | 'left' | 'right' | No | 'top' | Side of the target the tooltip opens on. |
align | 'start' | 'center' | 'end' | No | 'center' | Alignment along the target's edge. |
positioning | PopupPositioning | No | `{ offset: 8 }` | Advanced positioning (Fluent's |
motion | MotionSlot | null | No | the fade above | The motion of the tooltip's surface (the portaled box; |
children | React.ReactElement | Yes | A single element that triggers the tooltip on hover and focus: it receives the | |
ref | React.Ref<HTMLElement> | No | Ref to the wrapper | |
slotProps | { content?: SlotPart<'span'>; beak?: SlotPart<'div'> } | No | Props for the element the Tooltip draws besides your child, by part, merged into the part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added, your ref beside its ref. Every attribute the Tooltip sets on the part is locked and keeps the Tooltip's value; you add the attributes it does not set. A part takes no |
Any other prop is passed to the element it renders (HTMLSpanElement).
Parts
contentbeak
Stable class names
| Part | Class |
|---|---|
root | wave-tooltip |
content | wave-tooltip__content |
beak | wave-tooltip__beak |