Tooltip
A short label shown while its trigger is hovered or focused, on Base UI Tooltip. Tooltips are visual only: screen readers don’t announce them, and touch screens don’t show them. Use them to repeat or expand on something the trigger already says, never for the only copy of essential information. The repository link in this site’s header uses one.
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@blocks/design-system'From a Server Component, import the parts by name; client-authored code can use Tooltip.Trigger, Tooltip.Content and Tooltip.Provider.
Icon-only actions
An icon-only trigger needs its own aria-label; the tooltip shows a longer description to sighted readers. Wrap neighbouring tooltips in TooltipProvider so moving between them shows the next one at once.
Source · tooltip/icon-actions.tsx
import { Button, Stack, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@blocks/design-system'
import { Copy, Download } from 'lucide-react'
// A Server Component: named parts. The provider shares the delay, so moving
// between neighbouring actions shows the next tooltip at once.
export default function IconActions() {
return (
<TooltipProvider>
<Stack direction="row" gap="sm">
<Tooltip>
<TooltipTrigger render={<Button type="button" variant="ghost" aria-label="Copy readings" />}>
<Copy aria-hidden size={16} />
</TooltipTrigger>
<TooltipContent>Copy the last 24 hours as CSV</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger render={<Button type="button" variant="ghost" aria-label="Download readings" />}>
<Download aria-hidden size={16} />
</TooltipTrigger>
<TooltipContent>Download the full season</TooltipContent>
</Tooltip>
</Stack>
</TooltipProvider>
)
}Placement
side, align and sideOffset on the content place it; it flips to stay in view. Like other popups it takes container for themed subtrees.
Source · tooltip/placement.tsx
'use client'
import { Button, Tooltip } from '@blocks/design-system'
// Client-authored: the dot API and a placement.
export default function Placement() {
return (
<Tooltip>
<Tooltip.Trigger render={<Button type="button" />}>Resync station</Tooltip.Trigger>
<Tooltip.Content side="right">Fetches the last 24 hours again</Tooltip.Content>
</Tooltip>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
actionsRef | RefObject<TooltipRootActions | null> | — | A ref to imperative actions. - `unmount`: Unmounts the tooltip popup. - `close`: Closes the tooltip imperatively when called. |
children | ReactNode | PayloadChildRenderFunction<unknown> | — | The content of the tooltip. This can be a regular React node or a render function that receives the `payload` of the active trigger. |
defaultOpen | boolean | false | Whether the tooltip is initially open. To render a controlled tooltip, use the `open` prop instead. |
defaultTriggerId | string | null | — | ID of the trigger that the tooltip is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open tooltip. |
disabled | boolean | false | Whether the tooltip is disabled. |
disableHoverablePopup | boolean | false | Whether the tooltip contents can be hovered without closing the tooltip. |
handle | TooltipHandle<unknown> | — | A handle to associate the tooltip with a trigger. If specified, allows external triggers to control the tooltip's open state. Can be created with the Tooltip.createHandle() method. |
onOpenChange | ((open: boolean, eventDetails: TooltipRootChangeEventDetails) => void) | — | Event handler called when the tooltip is opened or closed. |
onOpenChangeComplete | ((open: boolean) => void) | — | Event handler called after any animations complete when the tooltip is opened or closed. |
open | boolean | — | Whether the tooltip is currently open. |
trackCursorAxis | "none" | "both" | "x" | "y" | 'none' | Determines which axis the tooltip should track the cursor on. |
triggerId | string | null | — | ID of the trigger that the tooltip is associated with. This is useful in conjunction with the `open` prop to create a controlled tooltip. There's no need to specify this prop when the tooltip is uncontrolled (that is, when the `open` prop is not set). |
| Prop | Type | Default | Description |
|---|---|---|---|
closeDelay | number | — | How long to wait before closing a tooltip. Specified in milliseconds. |
delay | number | — | How long to wait before opening the tooltip on hover. Specified in milliseconds. |
timeout | number | 400 | Another tooltip will open instantly if the previous tooltip is closed within this timeout. Specified in milliseconds. |
| Prop | Type | Default | Description |
|---|---|---|---|
closeDelay | number | 0 | How long to wait before closing the tooltip. Specified in milliseconds. |
closeOnClick | boolean | true | Whether the tooltip should close when this trigger is clicked. |
delay | number | 600 | How long to wait before opening the tooltip on hover. Specified in milliseconds. |
disabled | boolean | false | If `true`, the tooltip will not open when interacting with this trigger. Note that this doesn't apply the `disabled` attribute to the trigger element. If you want to disable the trigger element itself, you can pass the `disabled` prop to the trigger element via the `render` prop. |
handle | TooltipHandle<unknown> | — | A handle to associate the trigger with a tooltip. |
payload | unknown | — | A payload to pass to the tooltip when it is opened. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipTriggerState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
align | "center" | "start" | "end" | 'center' | How to align the popup relative to the specified side. |
container | PortalContainer | — | Where the popup mounts. Defaults to `document.body`; pass an element inside a `data-ds-theme` subtree so the popup inherits its theme. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipPopupState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
side | "top" | "bottom" | "left" | "right" | "inline-end" | "inline-start" | 'top' | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. |
sideOffset | number | OffsetFunction | 0 | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. @example ```jsx <Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} /> ``` |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
Accessibility
- The trigger’s accessible name is what assistive technology hears; make it complete without the tooltip.
- A tooltip appears on keyboard focus as well as hover, and Escape hides it without moving focus.
- Don’t put links or buttons in a tooltip. Use a Popover when the content is interactive.