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
Tooltip 6 props
The label: a few words, with no links or buttons (use a rich tooltip for those).
Draw a 16×8px caret pointing at the anchor.
Ref to the outermost element.
Goes on the outermost element, which React Aria places against the anchor; the surface inside keeps its size whatever layout class lands here. Style the surface with
classNames.panel.Inline styles for the outermost element; React Aria's position wins over them.
Classes for each part, by slot.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
RichTooltip 9 props
Supporting text.
Subhead; it also names a persistent tooltip.
Action(s), usually a text
Button.Draw a 16×8px caret pointing at the anchor.
Ref to the outermost element.
Goes on the outermost element, which React Aria places against the anchor; the surface inside keeps its size whatever layout class lands here. Style the surface with
classNames.panel.Inline styles for the outermost element; React Aria's position wins over them.
Classes for each part, by slot.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
TooltipTrigger 9 props
The trigger (a library button or anything reading
TriggerContext), then a<Tooltip>.Milliseconds of hover before showing (Compose shows at once).
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 barsSide 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).Distance from the anchor in px: 4 for an anchor with a visual boundary, 8 for text.
Never show the tooltip.
Whether the tooltip is shown (controlled).
Whether the tooltip starts shown when uncontrolled.
RichTooltipTrigger 10 props
The trigger (a library button), then a
<RichTooltip>.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).
Distance from the anchor in px.
Milliseconds of hover before a transient tooltip shows.
Milliseconds before a transient tooltip hides after the pointer leaves.
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.Whether the tooltip is shown (controlled).
Whether the tooltip starts shown when uncontrolled.
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.
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-plain-tooltip-container-color | var(--md-sys-color-inverse-surface) | The container and its caret. | PlainTooltipTokens.ContainerColor |
--md-comp-plain-tooltip-container-shape | var(--md-sys-shape-corner-extra-small) | The corners. | PlainTooltipTokens.ContainerShape |
--md-comp-plain-tooltip-supporting-text-color | var(--md-sys-color-inverse-on-surface) | The label. | PlainTooltipTokens.SupportingTextColor |
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-rich-tooltip-container-color | var(--md-sys-color-surface-container) | The container and its caret. | RichTooltipTokens.ContainerColor |
--md-comp-rich-tooltip-container-shape | var(--md-sys-shape-corner-medium) | The corners. | RichTooltipTokens.ContainerShape |
--md-comp-rich-tooltip-container-elevation | var(--md-sys-elevation-level-2) | The shadow. | RichTooltipTokens.ContainerElevation |
--md-comp-rich-tooltip-subhead-color | var(--md-sys-color-on-surface-variant) | The subhead (`title`). | RichTooltipTokens.SubheadColor |
--md-comp-rich-tooltip-supporting-text-color | var(--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.
| Item | Status | Details |
|---|---|---|
| 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). |
Plain tooltip
BuiltVariant · Plain
Rich tooltip
BuiltVariant · Rich
Subhead, supporting text and two buttons
BuiltConfiguration · Rich configurations
Subhead, supporting text and one button
BuiltConfiguration · Rich configurations, Rich
Subhead and supporting text
BuiltConfiguration · Rich configurations, Rich
Supporting text and one button
BuiltConfiguration · Rich configurations
Supporting text and two buttons
BuiltConfiguration · Rich configurations
Persistent rich tooltip
BuiltUse case · Rich
Caret
Extensioncaretdraws a 16×8px pointer at the anchor, as Compose can; the spec shows none.Focus keeps a plain tooltip
ExtensionA 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 kBTooltipTrigger: 2.3 kB
M3 Expressive specs
- Variants
plain, rich
Differences from Compose
- Plain tooltips are
inverse-surfacewithbody-smalltext, up to 200px wide, 4px corners; rich tooltips aresurface-containerat level 2, up to 320px, 12px corners, with 12px above and 8px below the text when there is no subhead or action. openDelaydefaults to 0, because Compose shows at once;closeDelayis 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 totop, rich ones tobottom-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.