- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
Installation#
pnpm dlx shadcn@latest add @zui/tooltipThe CLI writes components/ui/tooltip.tsx, lib/motion.ts and lib/overlay.ts, installs
Text and Utils, and adds @rn-primitives/tooltip, @rn-primitives/portal,
react-native-reanimated and react-native-worklets. The content draws in the app's PortalHost; see Add a
portal host. Without one it draws nothing, and logs an error saying
so while the app is in development.
Usage#
import { Button } from '@/components/ui/button';
import { Text } from '@/components/ui/text';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';<Tooltip>
<TooltipTrigger asChild>
<Button variant="outline">
<Text>Hover</Text>
</Button>
</TooltipTrigger>
<TooltipContent>
<Text>Add to library</Text>
</TooltipContent>
</Tooltip>API reference#
TooltipProvider#
Takes delay, how long in ms the pointer rests on a trigger before the web opens its tooltip, for every Tooltip
inside it; 0 by default. A Tooltip outside a provider waits 600ms. On a device it does nothing.
Tooltip#
Takes every prop of React Native's View, plus onOpenChange(open), called each time it opens or closes. On the
web it opens while the pointer rests on its trigger or the trigger has focus. On a device, which has no pointer
to rest, a press on the trigger opens it and another closes it.
TooltipTrigger#
Takes every prop of React Native's Pressable. Pass asChild to make a Button the trigger. Focus returns to it
when the Tooltip closes.
TooltipContent#
Takes every prop of React Native's View, plus:
| Prop | Type | Default |
|---|---|---|
side | 'top' | 'right' | 'bottom' | 'left' | 'top' |
sideOffset | number | 4 |
align | 'start' | 'center' | 'end' | 'center' |
alignOffset | number | 0 |
portalHost | string | - |
side is the side of the trigger the label opens on, sideOffset its gap from the trigger in px, and align
lines it up with the trigger's start, centre or end, moved along by alignOffset. The label is drawn in the
foreground colour, up to 20rem wide, with an arrow toward the trigger, and announced as a tooltip. On a device accessibility focus moves into it
as it opens, and a press outside it, the Android back button and the iOS escape gesture (a two-finger Z) close
it. On the web the pointer leaving the trigger and Escape close it. It fades in while growing from 95% and
sliding 0.5rem away from the trigger over 150ms. When the system asks for reduced motion it appears at once.
Differences from upstream#
- Upstream's
renderprop becomesasChild, as on every native item. - A press opens the tooltip on a device, where upstream's opens on hover and focus alone.
- The Tooltip holds its own open state, so it takes no
openordefaultOpen: the primitive it is built on has no controlled mode. - The arrow sits halfway along the label's edge that faces the trigger, where upstream's points at the
trigger's centre: React Native's popup reports no position for it. It stays on the side asked for when a
web label flips for room, and is moved up by 7px where upstream computes half its size and 2px with
calc(). - On a device the label opens above or below its trigger, so
leftandrightopen it above. The web places it on any side, and flips it when there is no room. - On a device it goes at once when a press outside it, the back button or the escape gesture closes it: the primitive removes it as it closes. Closed by its trigger, it fades out.
- Upstream's animation runs whatever the system's motion setting. The native one is skipped when the system asks for reduced motion.
portalHostis added, for an app that draws overlays into aPortalHostof its own.