@biem/ui

Tooltip

A hint that tells users what a control does when they hover over it or focus it.

A tooltip shows a short hint next to its trigger, so users learn what a control does without leaving their task. It opens when users rest the mouse pointer on the trigger for 600 milliseconds, and at once when they move focus to the trigger with the keyboard. It stays open while the pointer is on the trigger or on the content, and it closes when the pointer or the focus leaves, when users press the trigger or outside of the tooltip, or when they press Escape. Touch input doesn't open the tooltip, so the hint must not hold anything that users need to finish their task. A TooltipProvider around several tooltips sets their delays in one place and opens the next tooltip at once while one of them is open or has just closed. The trigger is a button without styles of its own, so the examples render it as a Button. The content is at most 20rem wide and points to the trigger with an arrow.

Usage

tooltip-default.tsx
import { Button } from "@biem/ui/components/ui/button";
import {
	Tooltip,
	TooltipContent,
	TooltipTrigger,
} from "@biem/ui/components/ui/tooltip";

export function TooltipDefault() {
	return (
		<Tooltip>
			<TooltipTrigger render={<Button variant="outline"/>}>Reorder</TooltipTrigger>
			<TooltipContent>Order 24 cases from the warehouse</TooltipContent>
		</Tooltip>
	);
}

Examples

Top Side

Most controls have room above them, and a hint placed there leaves the content that follows in view. The tooltip opens on this side by default, and side set to "top" makes that choice explicit.

Right Side

Along a navigation at the left edge of the screen, a hint above an item would cover the item before it. With side set to "right", the hint opens beside the item and leaves the rest of the navigation readable.

Bottom Side

Controls in a page header sit close to the top edge of the screen, with little room above them. Set to "bottom", side opens the hint below the control, where the page offers the room it needs.

Left Side

Actions at the end of a table row sit near the right edge of the screen, and a hint above or below them would cover the neighboring rows. Through side set to "left", the hint opens at the height of its row and keeps the rows around it readable.

Keep Open on Click

A control that users press several times in a row, such as one that raises an order quantity step by step, still needs its hint after the first press. Usually a press on the trigger closes the tooltip, while closeOnClick set to false on the trigger keeps it open, so users can read the hint as they continue.

Cursor Tracking on X Axis

On a wide trigger, such as a bar that spans the deliveries of a whole week, a hint at its center can appear far from the pointer. Once trackCursorAxis is set to "x", the hint follows the pointer from side to side and stays where users are looking. When keyboard focus opens it, the hint remains at the trigger.

Provider

In a toolbar, users often move from one control to the next to find the one they need. A TooltipProvider around those tooltips sets their delays in one place, and while one hint is open, the next one appears without delay as the pointer moves on. Unless the provider sets a delay, even the first hint opens as soon as the pointer reaches its trigger.

Controlled

Pointing users to a control they have not used yet, for example after an update, calls for a hint that the application opens on its own. Through open and onOpenChange, the application holds the state of the tooltip, while hover, focus and Escape still work as users expect.

Disabled

A hint loses its purpose once its control states what it does, for example when a collapsed navigation expands and shows its labels. With disabled set on the tooltip, the hint no longer opens and an open one closes, while the control itself stays fully usable.

API Reference

Tooltip

Propopen
Typeboolean
Default–
DescriptionSets whether the tooltip is open and makes it controlled. Update it in onOpenChange.
PropdefaultOpen
Typeboolean
Defaultfalse
DescriptionOpens the tooltip at first render. The tooltip then tracks its open state itself.
ProponOpenChange
Type(open: boolean, eventDetails: TooltipRootChangeEventDetails) => void
Default–
DescriptionRuns when users open or close the tooltip. It receives the open state that follows.
ProponOpenChangeComplete
Type(open: boolean) => void
Default–
DescriptionRuns after the tooltip has opened or closed and its animations have finished.
Propdisabled
Typeboolean
Defaultfalse
DescriptionPrevents the tooltip from opening and closes it when it is open.
PropdisableHoverablePopup
Typeboolean
Defaultfalse
DescriptionCloses the tooltip as soon as the pointer leaves the trigger. Without it, the tooltip stays open while users move the pointer from the trigger onto the content.
ProptrackCursorAxis
Type"none" | "x" | "y" | "both"
Default"none"
DescriptionSets the axis on which the content follows the mouse pointer: "x" for the horizontal axis, "y" for the vertical axis and "both" for both. With "both", users can't move the pointer onto the content. A tooltip that focus opened stays at the trigger.
ProptriggerId
Typestring | null
Default–
DescriptionSets the ID of the trigger that a controlled tooltip is associated with. A tooltip without open doesn't need it.
PropdefaultTriggerId
Typestring | null
Default–
DescriptionSets the ID of the trigger that the tooltip is associated with when defaultOpen opens it at first render.
Prophandle
TypeTooltipHandle<unknown>
Default–
DescriptionConnects the tooltip with triggers that are rendered outside of it. Create the handle with Tooltip.createHandle() from @base-ui/react/tooltip.
PropactionsRef
TypeRefObject<TooltipRootActions | null>
Default–
DescriptionReceives the functions close and unmount. close closes the tooltip from code, and unmount removes its content from the DOM.
Propchildren
TypeReactNode | ((arg: { payload: unknown }) => ReactNode)
Default–
DescriptionHolds the parts of the tooltip. A function receives the payload of the trigger that opened the tooltip.

TooltipTrigger

Propdelay
Typenumber
Default600
DescriptionSets how many milliseconds the pointer must rest on the trigger before the tooltip opens. Inside a TooltipProvider, the delay of the provider replaces the default. Focus opens the tooltip without a delay.
PropcloseDelay
Typenumber
Default0
DescriptionSets how many milliseconds the tooltip stays open after the pointer has left the trigger and the content. Inside a TooltipProvider, the closeDelay of the provider replaces the default.
PropcloseOnClick
Typeboolean
Defaulttrue
DescriptionCloses the tooltip when users press the trigger, and keeps it closed when they press before the delay has passed. With false, the tooltip opens and stays open regardless of the press.
Propdisabled
Typeboolean
Defaultfalse
DescriptionPrevents users from opening the tooltip with this trigger. It doesn't disable the trigger element itself.
Prophandle
TypeTooltipHandle<unknown>
Default–
DescriptionConnects the trigger with a tooltip that it is rendered outside of. Pass the same handle to Tooltip.
Proppayload
Typeunknown
Default–
DescriptionPasses a value to the tooltip when this trigger opens it. A function as children of Tooltip receives it.
Propid
Typestring
Default–
DescriptionSets the ID of the trigger element. triggerId and defaultTriggerId of Tooltip refer to it.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the trigger with another component.

TooltipContent

Propside
Type"top" | "bottom" | "left" | "right" | "inline-end" | "inline-start"
Default"top"
DescriptionSets the side of the trigger that the content opens on. "inline-start" and "inline-end" follow the reading direction. The content moves to the opposite side when the chosen one has too little space, and to a side on the other axis when neither of the two has enough.
PropsideOffset
Typenumber | OffsetFunction
Default4
DescriptionSets the distance between the trigger and the content in pixels. A function receives the side, the alignment and the dimensions of the trigger and the content, and returns the distance.
Propalign
Type"start" | "center" | "end"
Default"center"
DescriptionSets where the content lines up with the trigger along the chosen side: at its start, its center or its end.
PropalignOffset
Typenumber | OffsetFunction
Default0
DescriptionMoves the content along the alignment axis by a number of pixels. A function receives the same data as the one for sideOffset and returns the offset.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the content with another component.

TooltipProvider

Propdelay
Typenumber
Default0
DescriptionSets how many milliseconds the pointer must rest on a trigger before its tooltip opens. It applies to every tooltip in the provider whose trigger sets no delay of its own. While a tooltip in the provider is open, the next one opens at once.
PropcloseDelay
Typenumber
Default–
DescriptionSets how many milliseconds a tooltip stays open after the pointer has left its trigger and its content. It applies to every tooltip in the provider whose trigger sets no closeDelay of its own.
Proptimeout
Typenumber
Default400
DescriptionSets how many milliseconds after a tooltip has closed the next tooltip in the provider still opens at once.
Propchildren
TypeReactNode
Default–
DescriptionHolds the tooltips that share the delays.