Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Tooltip

FreeNew

A tooltip that springs from its anchor side, with an arrow, a shortcut slot and instant handoff between neighbors.

Installation

pnpm dlx shadcn@latest add @viewport/tooltip

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

tooltip-demo.tsx
import { Bold, Code, Italic, Link2, List, Underline } from "lucide-react";
import { Tooltip, TooltipProvider } from "@/components/viewport/tooltip";

const tools = [
  { label: "Bold", shortcut: "⌘B", icon: Bold },
  { label: "Italic", shortcut: "⌘I", icon: Italic },
  { label: "Underline", shortcut: "⌘U", icon: Underline },
  { label: "Inline code", shortcut: "⌘E", icon: Code },
  { label: "Add link", shortcut: "⌘K", icon: Link2 },
  { label: "Bulleted list", shortcut: "⌘⇧8", icon: List },
];

export default function TooltipDemo() {
  return (
    <TooltipProvider>
      <div role="toolbar" aria-label="Formatting" className="flex items-center gap-0.5 rounded-xl border border-border bg-card p-1 shadow-sm">
        {tools.map(({ label, shortcut, icon: Icon }) => (
          <Tooltip key={label} content={label} shortcut={shortcut}>
            <button
              type="button"
              aria-label={label}
              className="grid size-9 place-items-center rounded-lg text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
            >
              <Icon className="size-4" aria-hidden />
            </button>
          </Tooltip>
        ))}
      </div>
    </TooltipProvider>
  );
}

Props

PropTypeDefault
content*React.ReactNode

What the tooltip says. Keep it to a few words.

—
shortcutstring

A keyboard shortcut shown after the text, e.g. `⌘K`.

—
side"top" | "right" | "bottom" | "left""top"
offsetnumber

Pixels between the trigger and the tooltip.

8
children*React.ReactNode

The element that triggers the tooltip. It must be focusable.

—
classNamestring—

Accessibility

  • Built on Radix Tooltip: shows on focus, closes on Escape, described-by wiring.
  • Stays open while the pointer moves onto it.
  • Appears without motion under reduced motion.