suiss/ui · Component
Tooltip
A small label that appears next to an element on hover or keyboard focus.
Tooltip is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
Tooltip wraps the tooltip primitive of the chosen base. TooltipTrigger is the element that shows the tooltip, and TooltipContent renders the dark label with an arrow in a portal, positioned beside the trigger. TooltipProvider shares open delays across a group of tooltips.
Use tooltips to name icon-only buttons or show a keyboard shortcut. Keep the text short and don't put essential information or interactive content in a tooltip; use Popover for that.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a TooltipProvider:
Examples
Sides
Set side on TooltipContent to place the tooltip on each of the four sides of its trigger.
With shortcut
Names an icon button and shows its keyboard shortcut by placing a Kbd inside TooltipContent.
Accessibility
- Tooltips open when the trigger is hovered or receives keyboard focus, and close when the pointer leaves.
Escapecloses an open tooltip while focus stays on the trigger.- A tooltip doesn't name its trigger. Give icon-only triggers their own
aria-label.
API Reference
TooltipProvider
Shares delay timing across the tooltips inside it.
| Prop | Type | Default |
|---|---|---|
delay | number | 0 |
Also accepts the props of the primitive part it wraps.
Wrap your app, or a toolbar of tooltips, in TooltipProvider. delay is how long to wait before opening a tooltip, in milliseconds. This wrapper sets it to 0, so tooltips open without waiting.
| Prop | Type | Default |
|---|---|---|
delayDuration | number | 0 |
Also accepts the props of the primitive part it wraps.
Wrap your app, or a toolbar of tooltips, in TooltipProvider. delayDuration is how long to wait before opening a tooltip, in milliseconds. This wrapper sets it to 0, so tooltips open without waiting. A Tooltip outside a TooltipProvider wraps itself in a provider with the default delay.
| Prop | Type | Default |
|---|---|---|
delay | number | 0 |
closeDelay | number | 0 |
Wrap your app, or a toolbar of tooltips, in TooltipProvider. delay and closeDelay are how long to wait before opening and closing a tooltip, in milliseconds. This wrapper sets delay to 0, so tooltips open without waiting.
Tooltip
The root that holds a tooltip's open state.
Also accepts the props of the primitive part it wraps.
TooltipTrigger
The element that shows the tooltip on hover or focus.
Also accepts the props of the primitive part it wraps.
Use the render prop on TooltipTrigger to render it as a Button.
Set asChild on TooltipTrigger to render a Button as the trigger.
The Button placed first inside Tooltip is the trigger.
TooltipContent
The positioned label with its arrow, rendered in a portal.
| Prop | Type | Default |
|---|---|---|
side | "top" | "bottom" | "left" | "right" | "inline-start" | "inline-end" | "top" |
sideOffset | number | 4 |
align | "start" | "center" | "end" | "center" |
alignOffset | number | 0 |
| Prop | Type | Default |
|---|---|---|
side | "top" | "right" | "bottom" | "left" | "top" |
sideOffset | number | 4 |
align | "start" | "center" | "end" | "center" |
alignOffset | number | 0 |
Also accepts the props of the primitive parts it wraps.
The tooltip opens above the trigger by default, 4px away. sideOffset and alignOffset are in pixels; align lines the tooltip up with the trigger along its side. The label uses bg-foreground with text-background, so it inverts against the page in both light and dark appearances.
Each part sets a data-slot, such as tooltip-trigger or tooltip-content, for styling. The popup and arrow set data-side.