Cómo funciona
The bubble is an ink pill (the text colour as background, the surface colour as text) with a caret and tabular digits. The wrapper is an inline-flex, relative <span> and the bubble sits against it with absolute positioning: no portal and no position: fixed, so it stays put in scaled containers (it does not flip, and an ancestor's overflow: hidden clips it). Neighbor skipping uses a module-level timestamp: if another tooltip closed within 300ms, this one appears instantly with no transition and the old bubble vanishes, so sweeping a row of icons shows one bubble that seems to slide. Events are caught on the wrapper by bubbling, so children need no ref forwarding.
Úsalo para
- Icon-only buttons such as bold, link, share and delete: add one line about what they do, plus the shortcut if there is one.
- Truncated text, abbreviations and status tags: hover to read the full text or an explanation.
- Next to a disabled button to say why it cannot be pressed (wrap it in a container).
Busca otra opción cuando
- Content with links or buttons: the bubble cannot be clicked or focused; use a popover.
- Information people must see (errors, rules, price notes): write it on the page, since touch devices have no hover.
- Where an ancestor has overflow: hidden and the bubble would stick out: it gets clipped; use a portal-based tooltip there.
- Long explanations: beyond two or three lines, use a help panel or a docs link.
Uso
import { Tooltip } from './Tooltip.jsx'
export function NoteToolbar() {
return (
<div role="toolbar" aria-label="Formatting">
{/* An icon button needs its own aria-label (the name); the tooltip adds detail */}
<Tooltip content="Bold" shortcut="⌘B">
<button type="button" aria-label="Bold" aria-pressed={bold} onClick={toggleBold}>
<BoldIcon />
</button>
</Tooltip>
<Tooltip content="Delete note: restorable from Trash for 7 days" placement="bottom" delay={200}>
<button type="button" aria-label="Delete note" onClick={remove}>
<TrashIcon />
</button>
</Tooltip>
</div>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
content | ReactNode | — | Tooltip content: keep it to one short sentence. Nothing is rendered when it is empty. |
shortcut | ReactNode | — | Optional keyboard hint, such as “⌘B”, shown as a small muted chip after the text inside a <kbd>. |
placement | 'top' | 'bottom' | 'left' | 'right' | 'top' | Which side of the child the bubble sits on, centered. It does not flip automatically. |
delay | number | 400 | How long a mouse hover waits before showing, in ms. Keyboard focus and the neighbor shortcut ignore it. |
disabled | boolean | false | Shows no bubble and injects no aria-describedby. |
open | boolean | — | Controlled: force it shown or hidden, such as an always-on onboarding hint. Otherwise hover and focus decide. |
onOpenChange | (open) => void | — | Called when the shown state changes (or, when controlled, when it asks to close). |
children | ReactElement | — | The element being described; exactly one. It receives aria-describedby, so a custom component must pass aria-* attributes to the DOM. |
...rest | HTMLAttributes<HTMLSpanElement> | — | Other attributes, such as className and style, go to the wrapping <span>. Use --ds-tooltip-max-width (default 240px) and --ds-tooltip-z (default 40) to adjust the bubble. |
Accesibilidad
- The bubble has role="tooltip" and the child references it with aria-describedby (from useId, merged with any existing value); it stays in the DOM, so screen readers can read it whenever the element is focused.
- Keyboard focus (:focus-visible) shows it immediately and blur hides it; focus from a mouse click does not, so it does not linger after pressing a button.
- Escape closes the current tooltip (listened on document, so hover-opened ones close too); only one tooltip is lit at a time.
- The bubble is pointer-events: none and not focusable, so it never blocks the page; keep its content plain text.
- It is a description, not a name: icon-only buttons still need their own aria-label. It does not appear on touch, so never put essential information only here.
Movimiento
Hover wait 400ms (delay); enter 160ms ease-out: opacity 0 to 1, scale 0.9 to 1 from the caret, plus 4px outward; exit 100ms ease-in. Neighbor skipping: within 300ms of another tooltip closing, it appears with no wait and no transition while the previous bubble vanishes. Keyboard focus has no wait and plays the enter. Reduced motion: fade only.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
Tooltip.jsxtooltip.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

