A popup that displays information related to an element when it receives keyboard focus or the mouse hovers over it.
Installation
Install the packages
Add the shadcn/ui component
Animate it
The CLI finds your shadcn/ui components through components.json, swaps their primitive imports for Animate UI's and removes the CSS animation classes Motion replaces.
Usage
Import the primitive from Animate UI instead of Radix UI. Everything else stays the same.
import { Tooltip } from '@animate-ui/react/primitives/radix-ui';
export function BoldButton() {
return (
<Tooltip.Provider delayDuration={0}>
<Tooltip.Root>
<Tooltip.Trigger aria-label="Bold">B</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content sideOffset={4}>
Bold
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
);
}Coming from the @radix-ui/react-tooltip package? Use the subpath: import * as TooltipPrimitive from '@animate-ui/react/primitives/radix-ui/tooltip'.
Animation
The motion of Animate UI v1's Tooltip, starting from 0.7, with a warm-up:
- Content grows from 0.7 and fades in, from the trigger (
--radix-tooltip-content-transform-origin), on a spring (stiffness 400, damping 29) that overshoots a little before it settles. - It closes the same way: it shrinks back to 0.7 on the same spring while it fades out, then unmounts.
- Tooltips warm up: once one is open, moving along a toolbar shows the next one at once, without its entrance, and hides the previous one at once. 300ms after the last one closed, the next one plays its entrance again. shadcn/ui gives each tooltip its own Provider, so the library's own grouping never sees it: Animate UI tracks it across all of its tooltips.
- Radix only opens it on hover for mouse-like pointers, and on keyboard focus.
- With
forceMount(on the Content or the Portal), the closed content stays in the DOM: it plays its exit, then is hidden andinert. - Open from the start (
defaultOpen), it plays the same entrance on page load, like v1. - With
followCursoron the Root, the content leans towards the pointer while it moves over the trigger, by half its offset from the trigger's center, on a spring (stiffness 200, damping 17): on both axes, or only'x'or'y', as in v1. Under reduced motion it follows without the spring. - Under reduced motion, it only fades (no scale).
API Reference
Every part takes exactly the props of Radix UI's Tooltip. Animate UI adds the animation props below.
Root
Radix UI props, plus:
| Prop | Type | Default |
|---|---|---|
followCursor? | boolean | 'x' | 'y' | false |
followCursorSpringOptions? | SpringOptions | { stiffness: 200, damping: 17 } |
Provider, Trigger, Portal, Arrow
Radix UI props only. They are not animated.
Content
Radix UI props, plus:
| Prop | Type | Default |
|---|---|---|
transition? | Transition | { type: 'spring', stiffness: 400, damping: 29 } |
exitTransition? | Transition | transition |