Skip to content

Tooltip

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

The box
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

NameTypeRequiredDefaultDescription
contentReact.ReactNodeYes

Content to display inside the tooltip (short, non-interactive text).

appearance'inverted' | 'normal'No'inverted'

Color treatment: inverted (dark surface in the light theme) or normal (the page background with a border).

openDelaynumberNo200

Milliseconds before the tooltip appears when the pointer rests on the child or the child receives keyboard focus (Fluent's showDelay; unlike Menu's and Popover's openDelay, it applies to focus too).

closeDelaynumberNo100

Milliseconds before it hides once the pointer has left the child and the tooltip (Fluent's hideDelay); blur and Escape hide it at once.

openbooleanNo

Controlled open state (Fluent's visible). The tooltip still asks to open on hover and focus (after openDelay) and to close on leave, blur and Escape through onOpenChange. The surface renders only in the browser: an open tooltip is closed in the server HTML and opens once it has hydrated.

defaultOpenbooleanNofalse

Initial open state for uncontrolled usage.

onOpenChange(open: boolean) => voidNo

Called with the new open state when it changes (Fluent's onVisibleChange). It has no details argument yet.

relationship'description' | 'label' | 'inaccessible'No'description'

How the tooltip relates to its child: description adds it to the child's aria-describedby; label adds it to the child's aria-labelledby, naming an icon-only button; inaccessible makes it a purely visual hint, for text that assistive technology already has (a visible label, an aria-label): the child gets no aria-describedby or aria-labelledby from the Tooltip and the hidden role="tooltip" text is not rendered. The surface still shows on hover and focus. Fluent's relationship.

withArrowbooleanNofalse

Draws a beak, the small triangle that points at the child (or positioning.target), on the surface. It takes the surface's fill and border. Fluent's withArrow.

asChildbooleanNofalse

Renders no wrapper element: the Tooltip's handlers (hover, focus and blur), its ref, id, aria-*, className, style and data-* merge onto the single child element instead, which is also the anchor the surface is placed against. The child must forward ref and spread its props (a component that does not is wrapped in the <span>, with a development warning). The hidden description and the surface render next to the child, not around it, so the child keeps its place in a flex or grid layout, an inline-block span no longer changes its box, and ref reaches the child, not a <span>. Fluent's Tooltip has no wrapper, which is the behavior of this prop; WaveUI keeps its <span> by default so existing layouts and the className of the wrapper keep working.

side'top' | 'bottom' | 'start' | 'end' | 'left' | 'right'No'top'

Side of the target the tooltip opens on. start/end follow the writing direction; the tooltip flips to the opposite side when there is not enough room.

align'start' | 'center' | 'end'No'center'

Alignment along the target's edge.

positioningPopupPositioningNo`{ offset: 8 }`

Advanced positioning (Fluent's positioning): offset, fitViewport, matchReferenceWidth, fallbackPlacements and target, an element or a VirtualElement to place the surface at instead of the child (hover and focus on the child still show it; hold the element in state or pass a ref object). side and align stay separate props. The hover bridge across the gap covers the default 8px, so a larger offset leaves a gap the pointer cannot cross. The surface hides while its anchor is scrolled out of view or clipped.

motionMotionSlot | nullNothe fade above

The motion of the tooltip's surface (the portaled box; className stays on the wrapper <span>). By default it fades in over 100 ms and out over 100 ms with the easy-ease curve, without a slide; under reduced motion it appears and disappears at once. null turns the motion off (the surface still renders its data-presence phases, which then end at once); a class string or { className } replaces the default classes with yours (see MotionSlot), also under a WaveProvider with motion="none", which otherwise turns the default off. A WaveUI addition: Fluent's Tooltip has no motion.

childrenReact.ReactElementYes

A single element that triggers the tooltip on hover and focus: it receives the aria-describedby/aria-labelledby, plus any id and aria-* props given to the Tooltip (a Fragment around one element counts as that element). Other children are wrapped in a described <span> with a development warning, and their first focusable element gets the relationship.

refReact.Ref<HTMLElement>No

Ref to the wrapper <span> (the positioning anchor); with asChild, to the child element.

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 children. The part is Fluent UI's content slot, whose element is the surface: here content takes the text, and slotProps.content the element's props.

Any other prop is passed to the element it renders (HTMLSpanElement).

Parts

  • content
  • beak

Stable class names

PartClass
rootwave-tooltip
contentwave-tooltip__content
beakwave-tooltip__beak