Skip to content

Tooltip

A plain label on hover or focus, or a rich tooltip with a subhead and an action.

import { Tooltip, RichTooltip, TooltipTrigger, RichTooltipTrigger } from '@windmorph/react';

Props

By name or description, across the 34 props below

Tooltip 6 props

  • childrentype ReactNodeRequired

    The label: a few words, with no links or buttons (use a rich tooltip for those).

  • carettype booleandefault false

    Draw a 16×8px caret pointing at the anchor.

  • reftype Ref<HTMLDivElement>

    Ref to the outermost element.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

RichTooltip 9 props

  • childrentype ReactNodeRequired

    Supporting text.

  • titletype ReactNode

    Subhead; it also names a persistent tooltip.

  • actiontype ReactNode

    Action(s), usually a text Button.

  • carettype booleandefault false

    Draw a 16×8px caret pointing at the anchor.

  • reftype Ref<HTMLDivElement>

    Ref to the outermost element.

Text

  • aria-labeltype string

    Name of a persistent tooltip when there is no title.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

TooltipTrigger 9 props

  • childrentype ReactNodeRequired

    The trigger (a library button or anything reading TriggerContext), then a <Tooltip>.

  • openDelaytype numberdefault 0

    Milliseconds of hover before showing (Compose shows at once).

  • closeDelaytype numberdefault 1500

    Milliseconds before hiding after the pointer leaves or a touch lifts (the spec's 1.5s).

  • placementtype "top" | "bottom" | "left" | "right" | "start" | "end" | "top-start" | "top-end" | "bottom-start" | "bottom-end"default "top", or "bottom" in app bars

    Side of the anchor the tooltip prefers; it flips when there's no room. Inside a TooltipPlacementContext, the context's side is the default ("bottom" in app bars).

  • offsettype numberdefault 4

    Distance from the anchor in px: 4 for an anchor with a visual boundary, 8 for text.

  • disabledtype booleandefault false

    Never show the tooltip.

  • opentype boolean

    Whether the tooltip is shown (controlled).

  • defaultOpentype booleandefault false

    Whether the tooltip starts shown when uncontrolled.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called when the tooltip shows or hides.

RichTooltipTrigger 10 props

  • childrentype ReactNodeRequired

    The trigger (a library button), then a <RichTooltip>.

  • persistenttype booleandefault false

    A persistent rich tooltip opens when the trigger is pressed and stays, even after the pointer leaves, until the trigger is pressed again, Escape, or a press anywhere outside it (on another element or on empty space), or focus moving to another element. It's a non-modal dialog: opening it leaves focus on the trigger, and it comes next in the Tab order (trigger → its links and buttons → the rest of the page) without trapping focus. A transient one (the spec's default) works like a plain tooltip: hover, focus or a touch long press opens it, and it leaves 1.5s after the pointer or focus does.

  • placementtype "top" | "bottom" | "left" | "right" | "start" | "end" | "top-start" | "top-end" | "bottom-start" | "bottom-end"default "bottom-start"

    Bottom right of the anchor in left-to-right layouts (the spec).

  • offsettype numberdefault 4

    Distance from the anchor in px.

  • openDelaytype numberdefault 0

    Milliseconds of hover before a transient tooltip shows.

  • closeDelaytype numberdefault 1500

    Milliseconds before a transient tooltip hides after the pointer leaves.

  • disabledtype booleandefault false

    The trigger opens nothing: a transient tooltip ignores hover, focus and long press, and a persistent one's trigger works as a plain button, without aria-expanded.

  • opentype boolean

    Whether the tooltip is shown (controlled).

  • defaultOpentype booleandefault false

    Whether the tooltip starts shown when uncontrolled.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called when the tooltip shows or hides.

Tokens

M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.

Tooltip tokens (md-comp-plain-tooltip)
VariableDefaultPaintsCompose
--md-comp-plain-tooltip-container-colorvar(--md-sys-color-inverse-surface)The container and its caret.PlainTooltipTokens.ContainerColor
--md-comp-plain-tooltip-container-shapevar(--md-sys-shape-corner-extra-small)The corners.PlainTooltipTokens.ContainerShape
--md-comp-plain-tooltip-supporting-text-colorvar(--md-sys-color-inverse-on-surface)The label.PlainTooltipTokens.SupportingTextColor
Tooltip tokens (md-comp-rich-tooltip)
VariableDefaultPaintsCompose
--md-comp-rich-tooltip-container-colorvar(--md-sys-color-surface-container)The container and its caret.RichTooltipTokens.ContainerColor
--md-comp-rich-tooltip-container-shapevar(--md-sys-shape-corner-medium)The corners.RichTooltipTokens.ContainerShape
--md-comp-rich-tooltip-container-elevationvar(--md-sys-elevation-level-2)The shadow.RichTooltipTokens.ContainerElevation
--md-comp-rich-tooltip-subhead-colorvar(--md-sys-color-on-surface-variant)The subhead (`title`).RichTooltipTokens.SubheadColor
--md-comp-rich-tooltip-supporting-text-colorvar(--md-sys-color-on-surface-variant)The supporting text.RichTooltipTokens.SupportingTextColor

Spec status

Built to the M3 Expressive tooltip spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Plain tooltip

    Built

    Variant · Plain

  • Rich tooltip

    Built

    Variant · Rich

  • Subhead, supporting text and two buttons

    Built

    Configuration · Rich configurations

  • Subhead, supporting text and one button

    Built

    Configuration · Rich configurations, Rich

  • Subhead and supporting text

    Built

    Configuration · Rich configurations, Rich

  • Supporting text and one button

    Built

    Configuration · Rich configurations

  • Supporting text and two buttons

    Built

    Configuration · Rich configurations

  • Persistent rich tooltip

    Built

    Use case · Rich

  • Caret

    Extension

    caret draws a 16×8px pointer at the anchor, as Compose can; the spec shows none.

  • Focus keeps a plain tooltip

    Extension

    A tooltip shown by keyboard focus stays until blur or Escape rather than leaving after Compose's timeout (WCAG 1.4.13).

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • Tooltip, RichTooltip, RichTooltipTrigger: 18.3 kB
  • TooltipTrigger: 2.3 kB

M3 Expressive specs

Variants
plain, rich

Differences from Compose

  • Plain tooltips are inverse-surface with body-small text, up to 200px wide, 4px corners; rich tooltips are surface-container at level 2, up to 320px, 12px corners, with 12px above and 8px below the text when there is no subhead or action.
  • openDelay defaults to 0, because Compose shows at once; closeDelay is the spec's 1.5s.
  • Both sit 4px from the anchor (offset; use 8 for text anchors, and the optional 16×8 caret adds 8px) and keep 8px from the screen edge. Plain tooltips default to top, rich ones to bottom-start (bottom right in left-to-right layouts); in a top app bar or search app bar, plain tooltips open below (TooltipPlacementContext). At the screen edge they keep their natural width and move inside the margin. They expand from the anchor's side along one axis while fading in, rather than scaling, since the spec avoids scale motion.