A Radix tooltip with an arrow, side offset and fade and zoom transitions that opens on hover and keyboard focus. Works standalone or under a shared provider.
import { Bold, Italic, Link } from "lucide-react"
import { buttonVariants } from "@/components/ballmac/button"
import { Kbd, KbdGroup } from "@/components/ballmac/kbd"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ballmac/tooltip"
const tools = [
{ label: "Bold", icon: Bold, keys: ["⌘", "B"] },
{ label: "Italic", icon: Italic, keys: ["⌘", "I"] },
{ label: "Insert link", icon: Link, keys: ["⌘", "K"] },
]
export default function TooltipDemo() {
return (
<TooltipProvider>
<div role="toolbar" aria-label="Formatting" className="flex items-center gap-1 rounded-lg border bg-card p-1">
{tools.map(({ label, icon: Icon, keys }) => (
<Tooltip key={label}>
<TooltipTrigger className={buttonVariants({ variant: "ghost", size: "icon-sm" })} aria-label={label}>
<Icon />
</TooltipTrigger>
<TooltipContent>
{label}
<KbdGroup>
{keys.map((key) => (
<Kbd key={key} size="sm">
{key}
</Kbd>
))}
</KbdGroup>
</TooltipContent>
</Tooltip>
))}
</div>
</TooltipProvider>
)
}Installation
The default, and what a Radix-style project installs.
$ pnpm dlx shadcn@latest add @ballmac/tooltipInstall the dependencies.
$ pnpm add radix-uiCopy the source into your project.
components/ballmac/tooltip.tsx// Ballmac UI: Tooltip. https://ui.ballmac.com/components/tooltip // Based on shadcn/ui's Tooltip (MIT, Copyright (c) 2023 shadcn), restyled with an arrow and tw-animate-css transitions. "use client" import * as React from "react" import { Tooltip as TooltipPrimitive } from "radix-ui" import { cn } from "@/lib/utils" type TooltipProviderProps = React.ComponentProps<typeof TooltipPrimitive.Provider> & { /** Milliseconds from pointer enter until the tooltip opens. */ delayDuration?: number } function TooltipProvider({ delayDuration = 200, ...props }: TooltipProviderProps) { return <TooltipPrimitive.Provider data-slot="tooltip-provider" delayDuration={delayDuration} {...props} /> } /** A tooltip. Wraps itself in a TooltipProvider, so it works standalone; add one provider higher up to share delays. */ function Tooltip(props: React.ComponentProps<typeof TooltipPrimitive.Root>) { return ( <TooltipProvider> <TooltipPrimitive.Root data-slot="tooltip" {...props} /> </TooltipProvider> ) } function TooltipTrigger(props: React.ComponentProps<typeof TooltipPrimitive.Trigger>) { return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} /> } type TooltipContentProps = React.ComponentProps<typeof TooltipPrimitive.Content> & { /** Show the pointer arrow. */ arrow?: boolean /** Distance in px between the trigger and the tooltip. */ sideOffset?: number } function TooltipContent({ className, sideOffset = 6, arrow = true, children, ...props }: TooltipContentProps) { return ( <TooltipPrimitive.Portal> <TooltipPrimitive.Content data-slot="tooltip-content" sideOffset={sideOffset} className={cn( "z-50 flex w-fit max-w-[min(20rem,calc(100vw-2rem))] origin-(--radix-tooltip-content-transform-origin) items-center gap-2 text-balance rounded-md bg-foreground px-2.5 py-1.5 text-xs leading-snug text-background shadow-[0_4px_12px_-2px_rgb(0_0_0/0.2)]", "animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 motion-reduce:animate-none", "data-[side=bottom]:slide-in-from-top-1 data-[side=left]:slide-in-from-right-1 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-1", className )} {...props} > {children} {arrow ? ( <TooltipPrimitive.Arrow data-slot="tooltip-arrow" width={10} height={5} className="fill-foreground" /> ) : null} </TooltipPrimitive.Content> </TooltipPrimitive.Portal> ) } export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type TooltipContentProps, type TooltipProviderProps }Update the import paths to match your project setup.
$ pnpm dlx shadcn@latest add https://ui.ballmac.com/r/base/tooltip.jsonInstall the dependencies.
$ pnpm add @base-ui/react@^1.9.0Add the Ballmac items it builds on (their Base UI versions where they have one).
$ pnpm dlx shadcn@latest add https://ui.ballmac.com/r/base/positioner.jsonCopy the source into your project.
components/ballmac/tooltip.tsx// Ballmac UI: Tooltip. https://ui.ballmac.com/components/tooltip // Based on shadcn/ui's Tooltip (MIT, Copyright (c) 2023 shadcn), restyled with an arrow and tw-animate-css transitions. "use client" import * as React from "react" import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip" import { splitPositioner } from "@/lib/ballmac/positioner" import { cn } from "@/lib/utils" type TooltipProviderProps = React.ComponentProps<typeof TooltipPrimitive.Provider> & { /** Milliseconds from pointer enter until the tooltip opens. */ delayDuration?: number } function TooltipProvider({ delayDuration = 200, ...props }: TooltipProviderProps) { return <TooltipPrimitive.Provider delay={delayDuration} {...props} /> } // Base UI does not link a trigger to its tooltip. The root keeps the open state and an id here so the trigger can say aria-describedby while it is open. const TooltipContext = React.createContext<{ id: string; open: boolean }>({ id: "", open: false }) /** A tooltip. Wraps itself in a TooltipProvider, so it works standalone; add one provider higher up to share delays. */ function Tooltip({ onOpenChange, open: openProp, defaultOpen, ...props }: React.ComponentProps<typeof TooltipPrimitive.Root>) { const id = React.useId() const [own, setOwn] = React.useState(defaultOpen ?? false) const open = openProp ?? own const value = React.useMemo(() => ({ id, open }), [id, open]) return ( <TooltipProvider> <TooltipContext.Provider value={value}> <TooltipPrimitive.Root data-slot="tooltip" open={openProp} defaultOpen={defaultOpen} onOpenChange={(next, details) => { setOwn(next) onOpenChange?.(next, details) }} {...props} /> </TooltipContext.Provider> </TooltipProvider> ) } function TooltipTrigger(props: React.ComponentProps<typeof TooltipPrimitive.Trigger>) { const { id, open } = React.useContext(TooltipContext) return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" aria-describedby={open ? id : undefined} {...props} /> } const arrowClass = "data-[side=bottom]:-top-[5px] data-[side=left]:-right-[8px] data-[side=left]:rotate-90 data-[side=right]:-left-[8px] data-[side=right]:-rotate-90 data-[side=top]:-bottom-[5px] data-[side=top]:rotate-180" // rtl-fixed: the arrow sits on the physical edge that `side` names type TooltipContentProps = Omit<React.ComponentProps<typeof TooltipPrimitive.Popup>, "className"> & Pick<React.ComponentProps<typeof TooltipPrimitive.Positioner>, "side" | "align" | "alignOffset" | "collisionPadding"> & { className?: string /** Show the pointer arrow. */ arrow?: boolean /** Distance in px between the trigger and the tooltip. */ sideOffset?: number } function TooltipContent({ className, sideOffset = 6, arrow = true, children, ...rest }: TooltipContentProps) { const [position, props] = splitPositioner(rest) const { id } = React.useContext(TooltipContext) return ( <TooltipPrimitive.Portal> <TooltipPrimitive.Positioner sideOffset={sideOffset} className="z-50" {...position}> <TooltipPrimitive.Popup data-slot="tooltip-content" id={id} role="tooltip" className={cn( "flex w-fit max-w-[min(20rem,calc(100vw-2rem))] origin-(--transform-origin) items-center gap-2 text-balance rounded-md bg-foreground px-2.5 py-1.5 text-xs leading-snug text-background shadow-[0_4px_12px_-2px_rgb(0_0_0/0.2)]", "transition-[opacity,scale] duration-150 data-starting-style:scale-95 data-starting-style:opacity-0 data-ending-style:scale-95 data-ending-style:opacity-0 motion-reduce:transition-none", className )} {...props} > {children} {arrow ? ( <TooltipPrimitive.Arrow data-slot="tooltip-arrow" className={arrowClass}> <svg width="10" height="5" viewBox="0 0 10 5" aria-hidden="true" className="fill-foreground block"> <path d="M0 5 L5 0 L10 5 Z" /> </svg> </TooltipPrimitive.Arrow> ) : null} </TooltipPrimitive.Popup> </TooltipPrimitive.Positioner> </TooltipPrimitive.Portal> ) } export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type TooltipContentProps, type TooltipProviderProps }Update the import paths to match your project setup.
Usage
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ballmac/tooltip"The full example is in the Code tab above.
API reference
<TooltipProvider>
| Prop | Type | Default |
|---|---|---|
delayDurationMilliseconds from pointer enter until the tooltip opens. | number | 200 |
<TooltipContent>
| Prop | Type | Default |
|---|---|---|
arrowShow the pointer arrow. | boolean | true |
sideOffsetDistance in px between the trigger and the tooltip. | number | 6 |
Also accepts the standard attributes of its root element.
Accessibility
| Key | Action |
|---|---|
| Tab (focus trigger) | Opens the tooltip |
| Escape | Closes the tooltip |
Quality scorecard
Every applicable check passes
Measured in Chromium 153.0.8010.12 on October 19, 2026, on version 1.0.0, across 1 example.
Passed: Accessibility scan
No serious or critical issues in light and dark, on a phone and a desktop (axe-core 4.13.0, WCAG 2.1 AA and best-practice rules).
Passed: Small screens
No sideways scrolling at 360, 390 or 1280 px wide.
Passed: Reduced motion
No endless animation to begin with.
Passed: Right to left
Mirrors correctly in Arabic, Hebrew, Persian and Urdu layouts (0% of elements off the mirror, limit 15%).
Passed: Clean console
No console errors or React hydration errors while loading.
Passed: Keyboard
3 tab stops, each showing a visible change when it takes focus. 2 documented keys.
Not applicable: Loading, empty and error
Does not show data or take submissions.
Passed: Automated tests
Covered by tooltip.test.tsx.
For information: Footprint
1.0 KB of source (gzip) in 1 file. Installs radix-ui.
Automated checks find a subset of problems and do not replace testing with a screen reader and a keyboard in your own app. What they miss.
Use with AI
Short text hint for a control, shown on hover and focus. Compose Tooltip > TooltipTrigger (style it with buttonVariants and give icon triggers an aria-label) + TooltipContent. Put Kbd inside the content for shortcut hints. With the shadcn MCP server set up (guide), ask your agent:
Add the Ballmac UI Tooltip (@ballmac/tooltip) to this project with the shadcn MCP, then use it where it fits.
Use it for
- Naming icon-only buttons (still give the button an aria-label)
- Shortcut hints next to a label
- Clarifying truncated text
Not for
- Essential information or anything interactive (use a popover)
- Touch-first UIs where hover doesn't exist
- Error messages (show them inline)
Registry JSON: https://ui.ballmac.com/r/tooltip.json
Credits
Based on shadcn/ui Tooltip, adapted by Ballmac. Free to use in personal and commercial projects.
- npm
- radix-ui
- Registry
- shadcn/utils
Pairs well with
Button
A button with six variants, three sizes, a pill shape and a built-in loading state. buttonVariants() styles links the same way.
Kbd
Keyboard key and shortcut display built on the semantic <kbd> element, in three sizes, with KbdGroup for combinations like ⌘ ⇧ K. Adapts inside tooltips.
Avatar
A Radix avatar with image and initials fallback, three sizes, an optional presence dot, and AvatarGroup for overlapping stacks with a +N overflow counter.
Accordion
Vertically stacked disclosure sections on Radix Accordion, single or multiple open, with hairline dividers, a rotating plus and height animation.
Ballmac UI Pro
Need the whole screen, not one piece?
311 premium blocks (dashboards, settings, calendars, mail, shops, onboarding), a private shadcn registry and Figma tokens. Blocks that show data come with loading, empty and error states built in.
Not ready? Try three Pro blocks free
Leave your email and the blocks appear right here, ready to copy. Yours to use in any project.