Tooltip
A short explanation that appears on hover or focus.
Installation
pnpm dlx shadcn@latest add \
https://react-toolbox.io/r/tooltip.json \
https://react-toolbox.io/r/button.jsonNew here? Set up your project first. Styles, fonts, and required components are included. The command includes the components used by the examples below.
Usage
Compose TooltipRoot, TooltipTrigger, and TooltipContent, or use useTooltip. Keep essential information visible and give the trigger an accessible label independent of its tooltip.
Composition
TooltipProvider shares hover delays across triggers. Each TooltipRoot supports keyboard descriptions, collision handling, and touch long-press.
Show composition code
'use client';
import { Button } from '@/components/ui/material/button';
import { TooltipProvider, TooltipRoot, TooltipTrigger, TooltipPortal, TooltipContent } from '@/components/ui/material/tooltip';
export default function TooltipComposition() {
return (
<TooltipProvider delayDuration={300} skipDelayDuration={800}>
<div className="flex flex-wrap gap-4">
<TooltipRoot>
<TooltipTrigger asChild>
<Button>Archive</Button>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent>Move this project to the archive</TooltipContent>
</TooltipPortal>
</TooltipRoot>
<TooltipRoot>
<TooltipTrigger asChild>
<Button>Duplicate</Button>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent>Create a copy of this project</TooltipContent>
</TooltipPortal>
</TooltipRoot>
</div>
</TooltipProvider>
);
}
State and callbacks
useTooltip manages hover, focus, and touch visibility internally. For controlled visibility, use TooltipRoot with open/onOpenChange.
API reference
Key props and defaults. Full types and inline documentation are included with the source in material/tooltip.
useTooltip
| Property | Type | Default |
|---|---|---|
tooltip | ReactNode | — |
tooltipDelay | number | 0 |
tooltipHideOnClick | boolean | true |
tooltipPosition | TooltipPosition | 'vertical' |
tooltipShowOnClick | boolean | false |
Material guidelines
- Use short, plain text to clarify an interactive control on hover, focus, or touch long-press. Tooltips do not contain links or other controls.
- Give the trigger its own accessible name. A tooltip supplements that name and should not carry instructions essential to completing the task.