Tooltip
FreeNewA 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.
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
| Prop | Type | Default |
|---|---|---|
| content* | React.ReactNodeWhat the tooltip says. Keep it to a few words. | — |
| shortcut | stringA keyboard shortcut shown after the text, e.g. `⌘K`. | — |
| side | "top" | "right" | "bottom" | "left" | "top" |
| offset | numberPixels between the trigger and the tooltip. | 8 |
| children* | React.ReactNodeThe element that triggers the tooltip. It must be focusable. | — |
| className | string | — |
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.