Skip to content
TopClass UI

Tooltip

One or two lines of plain text on hover or focus: the name of an icon-only control, or a label that truncates.

client - size not measured yet

Tooltip

client - size not measured yet

One or two lines of plain text on hover or focus: the name of an icon-only control, or a label that truncates.

Install

Try it

placement
delay
closeDelay

The code

tooltip.tsx
import { linkSimple } from 'topclassui/icons/link-simple'
import { Button } from 'topclassui/button'
import { Svg } from 'topclassui/svg'
import { TooltipPopup, TooltipRoot, TooltipTrigger } from 'topclassui/tooltip'

<TooltipRoot>
  <TooltipTrigger
    render={
      <Button variant="ghost" aria-label="Copy link">
        <Svg icon={linkSimple} />
      </Button>
    }
  />
  <TooltipPopup>Copy link</TooltipPopup>
</TooltipRoot>

Touch never shows a tooltip, so the trigger's own name must repeat the text: give an icon-only Button an aria-label.

Every state

4 states

Import from the package

topclassui/tooltip
import { TooltipRoot, TooltipPopup, TooltipTrigger } from 'topclassui/tooltip'

Install once:npm i topclassui@beta zod

Examples

  • Three flat parts, TooltipRoot, TooltipTrigger and TooltipPopup, and no bare Tooltip.
  • Anything with a link or a control is a Popover: the popup's children are typed as text, so an element is refused at compile time.
  • delay and closeDelay go on the trigger and are clamped to 0 to 10000 ms; left out, 600 and 0 apply, or the shared delay of the app's provider.
  • placement goes on the popup, top by default.
  • Put the trigger's text or icon inside the Button passed to render, never inside TooltipTrigger, so the label still truncates and the icon still gives way to the loading spinner.
basic
delays
long-label
with-count
placements
disabled
In Arabic, right to left

Props

TooltipRoot

No props of its own: it takes the attributes of the element it renders.

TooltipPopup

The props of TooltipPopup
PropTypeDefaultLimitsDescription
childrenTooltipText | readonly TooltipText[]--Text only, never an element: a link or a control belongs in a Popover (R-10.5-2).
placementtop | top-start | top-end | bottom | bottom-start | bottom-end | start | start-top | start-bottom | end | end-top | end-bottom"top"-TooltipPopup: the side and alignment it opens at; start and end mirror in Arabic.

TooltipTrigger

The props of TooltipTrigger
PropTypeDefaultLimitsDescription
closeDelaynumber, min 0, max 100000min 0, max 10000TooltipTrigger: milliseconds it stays open after the pointer leaves, clamped.
delaynumber, min 0, max 10000600min 0, max 10000TooltipTrigger: milliseconds of hover before it opens, clamped to the limits.

Keyboard and accessibility

The keyboard of Tooltip
KeysWhat it does
TabFocus on the trigger opens the tooltip.
EscapeCloses the tooltip. Inside a dialog, the next Escape closes the dialog.
  • Base UI links the popup to nothing, so the trigger's name carries the text, not the tooltip.
  • The popup's children are typed as text: an element, a link or a control is refused at compile time.

Right to left

start opens on the right and end on the left. The default, top, stays above.

Server and client

A client component: it renders on the server and hydrates in the browser.

Files: index.tsx, client.tsx.

On the chip: client - size not measured yet.