Skip to content
Slotted

Tooltip

A short hint about a control, shown while the pointer rests on it or the keyboard focuses it.

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { Tooltip, TooltipArrow, TooltipContent, TooltipDefaultsProvider,  TooltipLayer, TooltipTrigger } from '@slotted/react';

Variants

inverse, the default, paints the tooltip in the color opposite to the page, so it separates from a light page without an edge. surface paints the raised panel color with a hairline border, for a page that is already dark. Hover each button to compare them.

Placement

side names the edge of the trigger the tooltip prefers: top by default, bottom, and inline-start and inline-end, which follow the writing direction; left and right do not. align sets where the tooltip sits along that edge: start, center or end. When the preferred edge has no room, the tooltip flips to the opposite edge and slides along it to stay 8 pixels inside the viewport. The four buttons open above, below, before and after their trigger, and the last one aligns to the top of its trigger.

Delays

A hover opens the tooltip after openDelay, 600 milliseconds by default, so a pointer crossing a row of buttons opens nothing. After the pointer leaves, the tooltip stays for closeDelay, 150 milliseconds, which is the time the pointer has to move onto it. Keyboard focus never waits. Release hold keeps the defaults, Cancel order waits 1.2 seconds and stays 400 milliseconds, and Track parcel opens after 200 milliseconds. Once one tooltip closes, the next one opens without the wait for groupDelay, 400 milliseconds, so move between the buttons slowly to feel each delay. groupDelay is set on TooltipDefaultsProvider in React and through provideTooltipDefaults in Angular.

Icon-only buttons

An icon-only button has no text to name it. describes="label" makes the tooltip its accessible name: the trigger refers to the content with aria-labelledby instead of aria-describedby, and the layer is in the document from the start, closed, so the name exists before the first hover. Write the tooltip as the action the button performs. IconButton and slIconButton take the aria-labelledby the trigger writes in place of an aria-label.

UPS 1Z999AA10123456784

Disabled triggers

A button with the native disabled attribute receives no pointer events and no focus, so a tooltip on it never opens. Set disabled with focusableWhenDisabled on the button instead: it keeps its place in the tab order, carries aria-disabled="true" and refuses its press, and the tooltip can say why it is unavailable.

Keyboard focus

Focus from the keyboard opens the tooltip at once. A focus that comes from a pointer press does not, because the press is the control’s own action. Escape closes the tooltip and leaves focus on the trigger; Enter and Space activate the button and close it; Tab moves focus on and closes it. The line under the buttons prints the reason of each change: keyboard, escape, blur or pointer, from onOpenChange in React and (openChangeRequest) in Angular.

Tab to a button, then press Escape or Enter.

Controlled

Pass open and update it from onOpenChange in React, or bind [(open)] to a signal in Angular, when something outside the tooltip opens it or reads its state. Hover, focus, Escape and an outside press still open and close it, and every change goes through the handler. Show the cutoff opens the tooltip from another button.

The cutoff hint is closed.

Long content

The tooltip wraps at 18rem, 14rem at size="sm", and an unbroken string such as a return label breaks inside it instead of widening it. On a narrow screen the tooltip also narrows to the width left beside the viewport edge, so it never pushes the page sideways. Keep it to one or two sentences: a tooltip opens only on hover, focus or a long press, so it may never be the only place a fact is written. A paragraph, a link or a control belongs in a popover.

In a toolbar

A toolbar of icon buttons is where tooltips usually live. TooltipDefaultsProvider in React and provideTooltipDefaults in Angular set describes="label" and size="sm" once for every tooltip under them, and they hold the group window, so moving along the row pays the open delay once. The arrow keys move focus between the buttons, and each focused button shows its tooltip.

Accessibility

KeyEffectFocus
Escapedismisses the tooltipstays on the trigger
Tabmoves to the next focusable element; a tooltip opened by focus is dismissed when the trigger loses itthe next focusable element, never the layer
Shift+Tabmoves to the previous focusable element, under the same rulethe previous focusable element, never the layer
Enteractivates the trigger, which is the consumer's own control, and dismisses the tooltip while closeOnPress holdsstays on the trigger
Spaceactivates the trigger under the same rulestays on the trigger
  • The content has role="tooltip" and the trigger refers to it: with aria-describedby by default, and with aria-labelledby under describes="label". An icon-only button that its tooltip only describes has no name, and a screen reader announces it as “button”.
  • Escape closes the tooltip and leaves focus on the trigger. It reaches the topmost layer only, so a tooltip open over a popover closes first. Escape is the whole keyboard table of the WAI-ARIA tooltip pattern, and it meets WCAG 2.2 SC 1.4.13 Dismissible. The tooltip never takes focus and holds nothing focusable: content with a link or a button belongs in a Popover.
  • The pointer can move onto the tooltip without it closing, because the gap between the trigger and the surface is the padding of the layer, not empty page (SC 1.4.13 Hoverable). Nothing closes the tooltip on a timer (Persistent).
  • A coarse pointer has no hover, so a long press opens the tooltip and a tap does not. A tooltip is supplementary: a fact reachable only by hover or long press is a fact many readers never reach, so a tooltip may never be the only place a fact is written.

API

Tooltip

Props

openboolean
The open state of a controlled tooltip. Update it from onOpenChange: the tooltip opens and closes only when the new value comes back. A tooltip that receives open stays controlled for as long as it is mounted.
defaultOpenbooleanDefault false
The state an uncontrolled tooltip starts in. It is read once, on mount.
variant'inverse' | 'surface'Default inverse
inverse paints the tooltip in the color opposite to the page, which needs no edge on a light page. surface paints the raised panel color with a hairline border, for a page that is already dark.
size'sm' | 'md'Default md
The type step: sm for dense rows such as toolbars and table cells, md elsewhere. Both steps follow the density of the region, because both read the control scale.
describes'description' | 'label' | 'none'Default description
How the trigger refers to the tooltip. description writes aria-describedby while the tooltip is open. label writes aria-labelledby, so the tooltip is the accessible name of an icon-only button, and it forces mount="eager" so the name exists before the first open. none writes no reference and hides the content from assistive technology, for a tooltip that repeats words the trigger already carries.
openOn'hover' | 'focus' | 'manual'Default hover
What opens the tooltip. hover opens it on pointer hover and on keyboard focus, and focus opens it without a delay. focus opens it on keyboard focus only. manual binds neither: the tooltip opens only through open or the handle.
side'top' | 'bottom' | 'inline-start' | 'inline-end' | 'left' | 'right'Default top
The edge of the trigger the tooltip prefers. inline-start and inline-end follow the writing direction of the layer, resolved at every measurement; left and right do not.
align'start' | 'center' | 'end'Default center
Where the tooltip sits along the edge it took: at the start of the trigger, at its center or at its end.
mount'active' | 'lazy' | 'eager'Default active
When the layer is in the document. active adds it on open and removes it after the exit animation, lazy keeps it after the first open, and eager renders it from the start.
strategy'absolute' | 'fixed'Default absolute
The CSS position of the layer. Use fixed for a trigger inside an overflow: hidden ancestor, and absolute for one inside a transformed ancestor.
arrowbooleanDefault true
Whether the layer draws the arrow.
hoverablebooleanDefault true
Whether the pointer can move from the trigger onto the tooltip without it closing. WCAG 2.2 SC 1.4.13 (Content on Hover or Focus) requires it, so turn it off only for content that meets the criterion another way.
closeOnPressbooleanDefault true
Whether pressing the trigger closes the tooltip, so it is not left over the dialog its button opened.
flipbooleanDefault true
Whether the tooltip moves to the opposite edge when the preferred edge has no room.
shiftbooleanDefault true
Whether the tooltip slides along its edge to stay inside the boundary.
hideWhenDetachedbooleanDefault true
Whether the layer hides while its trigger is outside the clipping ancestor. The tooltip hides without closing and shows again when the trigger comes back; the pointer leaving is what closes it.
portalbooleanDefault true
Whether the layer renders into the shared portal root at the end of the document. The portal root keeps the theme, color scheme, density and direction of the region the tooltip opened from.
disabledbooleanDefault false
Turns the tooltip off: it never opens and renders no layer. The disabled state of the trigger is set on the trigger itself.
whenClippedbooleanDefault false
Opens the tooltip only while the text of the trigger is cut off by its box, such as a column header truncated to “Op…”. The trigger is measured at the moment the tooltip would open, so a column dragged wider stops opening it.
openDelaynumberDefault 600
Milliseconds the pointer rests on the trigger before the tooltip opens. Keyboard focus opens it without waiting.
closeDelaynumberDefault 150
Milliseconds the tooltip stays after the pointer leaves, which is the time the pointer has to reach a hoverable tooltip. At 0 the pointer cannot reach it.
groupDelaynumberDefault 400
On TooltipDefaultsProviderMilliseconds after one tooltip closes during which the next one under the same provider opens without openDelay, so a row of buttons pays the wait once. It is set on the provider, because every tooltip under it shares the window.
touchDelaynumberDefault 500
Milliseconds a touch is held on the trigger before the tooltip opens. A tap does not open it, because a tap is the action of the control.
sideOffsetnumberDefault 0
Distance in pixels between the trigger and the tooltip beyond the standard gap. The standard gap is the padding of the layer, not empty page.
alignOffsetnumberDefault 0
Distance in pixels the tooltip moves along its edge from the aligned position.
collisionPaddingnumberDefault 8
The smallest distance in pixels between the tooltip and the edge of the boundary.
arrowPaddingnumberDefault 8
The smallest distance in pixels between the arrow and the rounded corners of the surface, where the surface would stop covering the base of the arrow.

Events

NamePayloadWhen
onOpenChange(open: boolean, request: TooltipChangeRequest)Called once per change, before the layer moves. The request carries value, previous, reason (pointer, keyboard, escape, blur or programmatic) and the originating event. request.cancel() refuses the change, and an uncontrolled tooltip then stays as it is.

Composition

render(props) => ReactNode
On TooltipTrigger, TooltipLayer, TooltipContent, TooltipArrowRenders the part into an element of your own. TooltipTrigger nearly always uses it, because the trigger is a control the page already has, such as a Button or an IconButton. The tooltip writes only the ARIA reference and data-open on the trigger, and no data-part, so the control keeps its own styling.
refRef<TooltipHandle>
open(), close() and reposition(), for the three actions a prop cannot express.
TooltipDefaultsProvidercomponent
On applicationSets any axis and any delay once for every tooltip under it, and holds the group window. A value set on one tooltip wins.
containerElement | nullDefault document.body
On TooltipDefaultsProviderThe element every layer under the provider renders into, set through setPortalContainer. An application shell with its own stacking context names it once.
native propsComponentPropsWithRef
On every partEach part accepts the props of its element. An onPointerEnter, onFocus or onClick written on the trigger runs before the handler of the tooltip, and event.preventDefault() in it skips that handler.

Parts

PartElementRequiredPurpose
rootdivYesThe layer, rendered by TooltipLayer. The positioner writes its position, left and top, and the layer carries the scale and fade of the entrance. Its padding is the gap between the trigger and the surface, so the pointer crosses onto a hoverable tooltip without leaving it. It carries data-ui="tooltip", data-side, data-align, data-open and data-detached.
contentdivYesThe painted surface, rendered by TooltipContent, with role="tooltip". The trigger refers to it with aria-describedby, or with aria-labelledby under describes="label".
arrowdivNoA rotated square, rendered by TooltipArrow, drawn over the edge of the surface so its two outer edges continue the outline. Place it beside TooltipContent inside TooltipLayer, not inside the content: the stylesheet selects it as a direct child of the layer. It is hidden from assistive technology.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every tooltip inside it.

Tooltip tokens

TokenDefault
--slotted-tooltip-arrow-size0.5rem
--slotted-tooltip-arrow-tip-radiusvar(--slotted-radius-xs, 2px)
--slotted-tooltip-backdrop-filternone
--slotted-tooltip-border-colorvar(--slotted-border-subtle, #e2e8f0)
--slotted-tooltip-gapvar(--slotted-space-4, 0.5rem)
--slotted-tooltip-measure18rem
--slotted-tooltip-measure-sm14rem
--slotted-tooltip-radiusvar(--slotted-radius-sm, 4px)
--slotted-tooltip-shadowvar(--slotted-shadow-xs)
--slotted-tooltip-surfacevar(--slotted-surface-inverse, #172033)
--slotted-tooltip-surface-raisedvar(--slotted-surface-raised, #ffffff)
--slotted-tooltip-textvar(--slotted-text-inverse, #f8fafc)
--slotted-tooltip-text-raisedvar(--slotted-text, #0f172a)

Theme tokens it reads

TokenDefault
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thin1px
--slotted-control-font-size-mdcomfortable 13px · compact 12px · dense 12px
--slotted-control-font-size-smcomfortable 12px · compact 12px · dense 12px
--slotted-control-gap-mdcomfortable 8px · compact 6px · dense 4px
--slotted-control-gap-smcomfortable 6px · compact 4px · dense 4px
--slotted-control-padding-inline-mdcomfortable 13px · compact 10px · dense 8px
--slotted-control-padding-inline-smcomfortable 10px · compact 8px · dense 6px
--slotted-duration-medium200ms
--slotted-duration-short120ms
--slotted-easing-entercubic-bezier(0.05, 0.7, 0.1, 1)
--slotted-easing-exitcubic-bezier(0.3, 0, 0.8, 0.15)
--slotted-font-family-sans'Geist Variable', ui-sans-serif, system-ui, sans-serif
--slotted-font-weight-regular400
--slotted-line-height-sm1.45
--slotted-radius-sm4px
--slotted-radius-xs2px
--slotted-shadow-xsSet per scheme by the theme
--slotted-space-20.25rem
--slotted-space-40.5rem
--slotted-surface-inverseSet per scheme by the theme
--slotted-surface-raisedSet per scheme by the theme
--slotted-textSet per scheme by the theme
--slotted-text-inverseSet per scheme by the theme
--slotted-z-index-popover1100