Tooltip

Slant / Overlays

A short description on hover and focus, never the only label.

Demo

Usage

@tuttn/slant
import { Button, Tooltip } from '@tuttn/slant'

// The tooltip describes; the trigger keeps its own name. An icon-only
// trigger needs its own aria-label.
<Tooltip content="Copies the share link">
  <Button icon aria-label="Copy link"><LinkIcon /></Button>
</Tooltip>

// It keeps its own state; pass open and onOpenChange to control it, or
// disabled to keep it from showing.
<Tooltip content="Saved 2 minutes ago" placement="bottom" delay={300} open={open} onOpenChange={setOpen}>
  <Button>Save</Button>
</Tooltip>

Props

PropTypeDefaultDescription
contentReactNode—What the tooltip says: a short description of the trigger. It is added to the trigger's description, never used as its name.
childrenReactElement—The trigger: one element that takes a ref and pointer and focus handlers, such as a Button. It keeps its own accessible name, so an icon-only trigger needs its own aria-label.
placementPlacement'top'The side of the trigger the tooltip sits on. It flips to the other side when this one lacks room.
delaynumber500How long the pointer or keyboard focus rests on the trigger before the tooltip shows, in milliseconds. Skipped while another tooltip shows or just after one hid.
openboolean—Whether the tooltip shows. Pass it with onOpenChange to control it; leave it out and the tooltip keeps its own state.
defaultOpenbooleanfalseWhether the tooltip starts shown, when uncontrolled.
onOpenChange(open: boolean) => void—Called with the new state whenever the tooltip asks to show or hide.
disabledbooleanfalseNever shows the tooltip. The trigger keeps its handlers and its description.
…restHTMLAttributes<HTMLDivElement>—The ref, id, className, style and other attributes go on the tooltip element (role="tooltip"), not the trigger. The trigger is your child element, which takes its own props.

A tooltip only ever describes its trigger. The trigger’s aria-describedby gains the tooltip’s id, after any id it already had, and its accessible name stays its own: an icon-only button still needs an aria-label, and the tooltip should add something the name doesn’t say. The tooltip element is rendered even while hidden, so the description always resolves. Nothing interactive belongs in a tooltip; use a Popover for that.

It shows after delay (500ms) when a mouse or pen rests on the trigger, or when the trigger gets keyboard focus (:focus-visible), so a click or a touch never brings it up. While one tooltip shows, or for a moment after it hid, the next shows without the wait and the first hides at once, so a pointer moving along a toolbar meets one at a time. It hides when the pointer leaves, after a short grace in which the pointer can move onto the tooltip and stay there; on blur; on a press of the trigger; and on Escape, which only the topmost layer answers, so Escape on a tooltip inside a popover or dialog hides the tooltip and leaves the rest open. disabled keeps it from showing and changes nothing else.

The tooltip renders in a portal above popovers and menus, carrying its root’s theme and direction. It sits on the side placement names, flips when that side lacks room, slides to stay in view, and follows the trigger when anything scrolls.