@akhatmirzo/ui

You are viewing docs for an older version

This page documents v0.2. The latest version is v0.3.

Go to the latest docs →

Tooltip

A short hint that appears on hover or focus, with an optional keyboard shortcut.

Import

import { Tooltip, TooltipProvider } from '@akhatmirzo/ui';

When to use

  • To explain an icon button — the most common case: put the action into words and show its shortcut (⌘C).
  • Short text only. No buttons or links inside — for interactive content, use a Popover.
  • Don't hide essential information. Tooltips never show on phones, so anything users must know belongs on the page itself.
  • Not a replacement for aria-label. Icon buttons still need an aria-label; the tooltip is an extra for sighted users.

TooltipProvider

Put one TooltipProvider at the root of your app: all tooltips share the same delay, and moving from one to the next opens it without a delay (try moving across the buttons above). Tooltips work without a provider too — each creates its own — you just lose that instant hand-off.

app/providers.tsx
'use client';

import { TooltipProvider } from '@akhatmirzo/ui';
import type { ReactNode } from 'react';

export function Providers({ children }: { children: ReactNode }) {
  return <TooltipProvider delay={300}>{children}</TooltipProvider>;
}

Sides

side is top (default), right, bottom or left. Near the edge of the screen, the tooltip flips to the opposite side.

Delay and long text

delay is how long to wait before opening, in ms. By default it comes from the provider (300). Text longer than 240px wraps to the next line — but a tooltip is best kept to a line or two.

On a disabled button

A disabled button doesn't fire events, so a tooltip can't attach to it directly. Wrap the button in a span with tabIndex={0} — keyboard users get the explanation too.

Controlled and disabled

Use open + onOpenChange to open the tooltip from code. disabled turns the tooltip off for a while and leaves the trigger as is. An empty content renders no tooltip either.

Props

Tooltip

The rest of the Radix Tooltip.Content props (alignOffset, avoidCollisions, onEscapeKeyDown ...) and className go to the tooltip panel.

PropTypeDefaultDescription
contentrequiredReactNode—Short text. When empty, no tooltip is shown
childrenrequiredReactElement—The trigger — a single element that accepts a ref and events
side'top' | 'right' | 'bottom' | 'left''top'Preferred side
align'start' | 'center' | 'end''center'Alignment along the trigger
sideOffsetnumber6Gap to the trigger, px
collisionPaddingnumber8Minimum distance from the screen edge, px
delaynumber—Open delay in ms (defaults to the provider, or 300)
shortcutstring[]—A Kbd next to the text: ['mod', 'C']
openboolean—Controlled mode
defaultOpenbooleanfalseOpen on first render
onOpenChange(open: boolean) => void—Called when it opens or closes
disabledbooleanfalseTurns the tooltip off

TooltipProvider

Also available as Tooltip.Provider.

PropTypeDefaultDescription
delaynumber300Open delay, ms
skipDelaynumber300Within this window, the next tooltip opens instantly, ms
childrenrequiredReactNode—Your app

Data attributes

AttributeOnValue
data-statepaneldelayed-open · instant-open · closed
data-sidepaneltop · right · bottom · left
data-slotpaneltooltip

Keyboard

KeyAction
Tab (focus)The tooltip shows when the trigger is focused
EscCloses the tooltip

Accessibility

  • Wiring. While open, the trigger points to the tooltip text with aria-describedby, so screen readers read the hint after the button's name.
  • Shows on keyboard focus, not only on hover.
  • Touch devices (no hover, coarse pointer) never open tooltips — a tap just activates the button.
  • Color. Tooltips use inverted colors (bg-text, text-background), so contrast holds in both light and dark mode.
  • Reduced motion. With prefers-reduced-motion, only a fade is used.

On this page