Skip to content

Components · Overlay

note:Copy source: not an npm package.

Tooltip

A small hint for icon-only controls: opens on hover and keyboard focus, dismisses with Escape, stays hoverable and supports a shortcut hint.

  • hover
  • focus
  • WCAG 1.4.13
Dependencies
None beyond React
Source
src/components/collection/tooltip/tooltip.tsx

Preview & code

Options

Last action: none

Hover, or Tab to a button: the hint appears and Escape dismisses it. Each button still has its own accessible name; the tooltip only adds a description.

When to use it

Icon-only buttons and dense toolbars benefit from a short hint, but a tooltip must work for keyboard and screen-reader users too, must be dismissible without moving away, and must not get in the way of touch.

Usage

  1. Copy src/components/collection/tooltip/tooltip.tsx into your project (from the Code tab above).
  2. Import it from where you placed it. In this repo that’s @/components/collection/tooltip/tooltip.
usage.tsxtsx
import { Tooltip } from "@/components/collection/tooltip/tooltip";​export function ThemeButton({ onToggle }: { onToggle: () => void }) {  return (    <Tooltip content="Toggle theme" shortcut="D" side="bottom">      <button type="button" aria-label="Toggle theme" onClick={onToggle}>◐</button>    </Tooltip>  );}

API

Tooltip props
PropTypeDefaultDescription
content* (required)ReactNode—Short, non-essential hint text.
children* (required)ReactElement—One focusable trigger (button or link) that accepts aria-describedby and has its own accessible name.
side"top" | "bottom""top"Preferred side. It flips to the other side when there isn't room in the viewport.
align"center" | "start" | "end""center"Horizontal alignment to the trigger. The bubble also shifts sideways to stay inside the viewport.
shortcutstring—A keyboard shortcut rendered as a kbd after the content, e.g. "D".
openDelaynumber300Hover delay in ms. Within 400ms of another tooltip closing it opens instantly and travels from the previous position; keyboard focus always opens immediately.
closeDelaynumber0Delay in ms before closing after the pointer leaves. Closing then takes a 100ms fade; the bubble stays hoverable because it sits inside the trigger's hover area.
forceOpenbooleanfalseShow it regardless of hover or focus, on every input type, e.g. for "Copied" feedback. Escape still hides it.
defaultOpenbooleanfalseStart open, for static previews. Hover, focus and Escape take over afterwards.
classNamestring—Classes on the wrapper span.

* required

Accessibility

Tab
Focusing the trigger shows the tooltip; moving focus away hides it.
Escape
Dismisses the tooltip without moving focus.
  • The tooltip has role="tooltip" and is linked with aria-describedby, so it's announced as a description of the trigger.
  • It opens on keyboard focus (focus-visible), not only on hover.
  • Dismissible (Escape), hoverable (pointer can move onto it) and persistent while hovered or focused, per WCAG 1.4.13.
  • Triggers keep their own accessible name; the tooltip never replaces a label.
  • It never opens on touch, where hover doesn't exist; transient feedback uses forceOpen instead.

Limits & tests

Limitations

  • Collision handling covers the viewport only (sideways shift and flip), not scrolling containers; keep content short.
  • Not for interactive content: use a popover or disclosure instead.
  • The neighbour grace period is shared through module state, so it spans every Tooltip on the page.

Tests

tests/e2e/components.spec.ts

  • Opens on keyboard focus and is linked via aria-describedby
  • Escape dismisses it while focus stays on the trigger
  • Opens on hover after the delay, and instantly on a neighbour within the grace period
  • Never opens on touch