Unified UI

Tooltip

A lightweight tooltip component for displaying contextual information on hover or focus. Built on Radix UI.

Overview

The Tooltip component provides contextual information when users hover over or focus on an element. It's built on Radix UI's Tooltip primitive with design system tokens for consistent styling.


Installation

Install the component via the CLI in one command.

npx @work-rjkashyap/unified-ui add tooltip
pnpm dlx @work-rjkashyap/unified-ui add tooltip
npx @work-rjkashyap/unified-ui add tooltip
bunx @work-rjkashyap/unified-ui add tooltip

If you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.

Or install the full package

Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.

npm install @work-rjkashyap/unified-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import {
	Tooltip,
	TooltipProvider,
} from "@work-rjkashyap/unified-ui";

Setup

Wrap your application (or a section of it) with TooltipProvider to enable tooltips. This configures shared delay and skip behavior for all tooltips within its scope.

import { TooltipProvider } from "@work-rjkashyap/unified-ui";

export default function RootLayout({ children }) {
	return <TooltipProvider>{children}</TooltipProvider>;
}

Examples

Basic Usage

The trigger element must be a single React element that can accept a ref. If you're wrapping a custom component, make sure it forwards refs.

Placement

Alignment

With Icon-Only Buttons

Toolbar Pattern


Arrow

By default, tooltips show a small arrow pointing toward the trigger. Set arrow={false} to hide it.

{
	/* With arrow (default) */
}
<Tooltip content="With arrow" arrow>
	<Button>Hover me</Button>
</Tooltip>;

{
	/* Without arrow */
}
<Tooltip content="No arrow" arrow={false}>
	<Button>Hover me</Button>
</Tooltip>;

Delay

Configure the open delay to control how quickly the tooltip appears. The TooltipProvider controls the shared delay for all tooltips in its scope.

{
	/* Fast — 200ms delay */
}
<TooltipProvider delayDuration={200}>
	<Tooltip content="Quick tooltip">
		<Button>Fast</Button>
	</Tooltip>
</TooltipProvider>;

{
	/* Slow — 700ms delay */
}
<TooltipProvider delayDuration={700}>
	<Tooltip content="Slow tooltip">
		<Button>Slow</Button>
	</Tooltip>
</TooltipProvider>;

You can also override the delay per tooltip:

<Tooltip content="Custom delay" delayDuration={0}>
	<Button>Instant</Button>
</Tooltip>

Rich Content

The content prop accepts any ReactNode, so you can render rich tooltip content.

<Tooltip
	content={
		<div className="flex flex-col gap-1">
			<p className="font-semibold text-xs">Keyboard Shortcut</p>
			<p className="text-xs text-muted-foreground">
				Press{" "}
				<kbd className="px-1 py-0.5 bg-muted rounded text-[10px]">
					Ctrl+S
				</kbd>{" "}
				to save
			</p>
		</div>
	}
>
	<Button>Save</Button>
</Tooltip>

Max Width

Tooltips have a default max width of 220px to keep content readable. Override with maxWidth.

<Tooltip
	content="This is a very long tooltip message that would normally wrap at the default max width."
	maxWidth={300}
>
	<Button>Wide tooltip</Button>
</Tooltip>

Props

Tooltip

PropTypeDefaultDescription
contentReactNoderequiredThe tooltip content. Can be a string or React node.
side"top" | "right" | "bottom" | "left""top"Which side the tooltip appears on.
align"start" | "center" | "end""center"Alignment along the side axis.
arrowbooleantrueWhether to show the arrow indicator.
sideOffsetnumber4Distance in px from the trigger.
maxWidthnumber220Maximum width of the tooltip in px.
delayDurationnumberOverride the provider's delay for this tooltip.
childrenReactElementrequiredThe trigger element (must accept a ref).

TooltipProvider

PropTypeDefaultDescription
delayDurationnumber400Open delay in ms for all tooltips in scope.
skipDelayDurationnumber300Time in ms before the delay resets after leaving a tooltip.
disableHoverableContentbooleanfalsePrevent tooltip from staying open when hovering over its content.

Accessibility

Built on @radix-ui/react-tooltip which provides full keyboard and screen reader support out of the box.

  • Keyboard accessible — Tooltips appear when the trigger receives keyboard focus and hide on blur.
  • Escape to dismiss — Pressing Escape closes the tooltip immediately.
  • ARIA attributes — The tooltip is linked to its trigger via aria-describedby (managed by Radix).
  • Screen reader support — The tooltip content is announced when the trigger is focused.
  • No focus steal — Tooltips don't trap focus. They supplement existing content without blocking interaction.
  • Hover intent — Configurable delay prevents tooltips from flickering during normal mouse movement.
  • Skip delay — After viewing one tooltip, subsequent tooltips open faster (controlled by skipDelayDuration).
  • The tooltip uses z-tooltip for proper layering above page content.
  • Animations are CSS-based (fade + scale) and respect prefers-reduced-motion.

Design Tokens

TokenUsage
--foregroundTooltip text color
--popoverTooltip background
--radius-mdTooltip border radius
--z-tooltipZ-index for tooltip layer
--shadow-smTooltip elevation shadow
--duration-fastAnimation timing for enter/exit

On this page