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
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
- Install the dependencies and add the
cnhelper:
- Copy the source into
components/ui/tooltip.tsx:
- Update the import paths to match your project.
Usage
Set side on TooltipContent to place the tooltip on another side; it opens above the trigger by default, 4px away. Place a Kbd inside TooltipContent to show a shortcut.
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.
Wrap your app, or a toolbar of tooltips, in TooltipProvider. This wrapper sets the provider's delay to 0, so tooltips open without waiting.
Examples
Sides
Places tooltips on each of the four sides of their triggers.
With shortcut
Names an icon button and shows its keyboard shortcut with Kbd.
API Reference
TooltipProvider
Shares delay timing across the tooltips inside it.
Also accepts the props of the primitive part it wraps.
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.
TooltipContent
The positioned label with its arrow, rendered in a portal.
Also accepts the props of the primitive parts it wraps.
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.
Notes
- Parts carry
data-slotattributes such astooltip-triggerandtooltip-content; the popup and arrow setdata-side. - The label uses
bg-foregroundwithtext-background, so it inverts against the page in both light and dark appearances. TooltipContentaccepts the positioner propsside,sideOffset,alignandalignOffset.