Skip to content
caliper ui docs

Components

Tooltip

A short hint that appears on hover or focus, never the only way to learn something.

Free
pnpm dlx shadcn@latest add @caliper/tooltip

INV-0417

Halden Analytics · issued 18 Sep

Amount
$4,280.00
Status
Paid 2 Oct

Rafael Abreu · Finance

Installs components/ui/tooltip.tsxDepends on @radix-ui/react-tooltipMotion none in component source

When to use

Use it for

  • Naming an icon-only button.
  • Showing a keyboard shortcut or a short clarification.

Skip it when

  • The text is long or interactive; use a popover or hover card.
  • Touch-only contexts where hover does not exist.

Decisions

Why it is built this way, so you know what to keep when you change your copy.

Behaviour

The first waits, neighbours follow at once
The first tooltip waits 300ms; moving along a toolbar shows the next immediately for half a second, so scanning icons does not mean waiting at each one.
The label cannot be hovered
Tooltip content ignores the pointer, so moving across a toolbar switches labels instead of getting stuck on the last one.

Usage

Never the only explanation
Touch screens have no hover. Anything people need to complete a task belongs on the page, not in a tooltip.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/tooltip

Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.

Usage

This is the code behind the preview above. It is built from Tooltip, TooltipTrigger, TooltipProvider and TooltipContent.

example.tsx
import { Bell, FileText, Inbox, Upload } from "lucide-react"
import { type ReactNode } from "react"
import { Avatar } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
import { cn } from "@/components/ui/lib/cn"

function Panel({ title, context, media, action, className, children }: { title: string; context: string; media?: ReactNode; action?: ReactNode; className?: string; children?: ReactNode }) {
  return (
    <section className={cn("grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}>
      <div className="flex items-center gap-3">
        {media}
        <div className="grid min-w-0 flex-1 gap-1">
          <p className="font-medium">{title}</p>
          <p className="text-sm text-muted-foreground">{context}</p>
        </div>
        {action}
      </div>
      {children}
    </section>
  );
}

export function IconTooltip() {
  const tools = [
    { label: "Duplicate", shortcut: "⌘D", icon: <FileText aria-hidden="true" /> },
    { label: "Download PDF", shortcut: "⌘⇧S", icon: <Upload aria-hidden="true" className="rotate-180" /> },
    { label: "Send to customer", shortcut: "⌘↵", icon: <Inbox aria-hidden="true" /> },
    { label: "Notifications", shortcut: "⌘N", icon: <Bell aria-hidden="true" /> },
  ];
  return (
    <TooltipProvider>
      <Panel title="INV-0417" context="Halden Analytics · issued 18 Sep" media={<Avatar name="Halden Analytics" shape="square" />}>
        <dl className="grid grid-cols-2 gap-4 text-sm">
          <div className="grid gap-0.5"><dt className="text-muted-foreground">Amount</dt><dd className="m-0 text-2xl font-medium tracking-tight tabular-nums">$4,280.00</dd></div>
          <div className="grid content-start justify-items-start gap-1.5"><dt className="text-muted-foreground">Status</dt><dd className="m-0"><Badge variant="success">Paid 2 Oct</Badge></dd></div>
        </dl>
        <div className="flex items-center justify-between gap-3 border-t border-border pt-5">
          <p className="text-sm text-muted-foreground">Rafael Abreu · Finance</p>
          <ButtonGroup aria-label="Invoice tools">
            {tools.map((tool) => (
              <Tooltip key={tool.label}>
                <TooltipTrigger asChild>
                  <Button variant="secondary" size="icon" aria-label={tool.label} aria-keyshortcuts={tool.shortcut}>{tool.icon}</Button>
                </TooltipTrigger>
                <TooltipContent shortcut={tool.shortcut}>{tool.label}</TooltipContent>
              </Tooltip>
            ))}
          </ButtonGroup>
        </div>
      </Panel>
    </TooltipProvider>
  );
}

API reference

Tooltip

component

No props of its own; it accepts the native props of its root element.

TooltipTrigger

component

No props of its own; it accepts the native props of its root element.

TooltipProvider

component

No props of its own; it accepts the native props of its root element.

TooltipContent

component

Also accepts the native props of its root element and a ref.

PropTypeDefaultDescription
shortcutstring—Keyboard shortcut shown after the label, e.g. "⌘D".

Accessibility

It is built on native elements, so roles and focus come from the browser.

Keyboard and focus handling comes from Radix tooltip: arrow keys move through items, Enter and Space select, and Escape closes and returns focus.

Motion

It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.

All Overlays & tabs examples