Tooltip
A floating label that provides supplementary information when an element is hovered or focused.
Overview
Tooltip is a compound component that renders a short text label when the user hovers or focuses a trigger element. Wrapping multiple tooltips with a shared Tooltip.Provider lets you coordinate delay and open behavior across them.
- Composed with a compound API:
Tooltip.Provider,Tooltip,Tooltip.Trigger,Tooltip.Content,Tooltip.Arrow - Wrapping a group of tooltips with
Tooltip.Providershares hover delay settings. - Supports
sideandalignpositioning props onTooltip.Content. Tooltip.Arrowrenders an arrow caret pointing toward the trigger.
Guidelines
- Use Tooltip for short, supplementary text labels — 1–2 sentences maximum.
- Tooltip content should not be essential for understanding the UI; it supplements the trigger label.
- For interactive content (links, buttons, forms), use Popover instead.
- Always wrap multiple nearby tooltips in a shared
Tooltip.Providerto coordinate hover delays.
Accessibility
- Tooltip content is exposed via
role="tooltip"with the trigger linked viaaria-describedby. - Appears on both hover and focus, ensuring keyboard users can access the tooltip content.
- Disappears when the trigger loses hover or focus, or when
Escapeis pressed. - Tooltip content should be supplementary — do not place critical information only in a tooltip, as some users may not discover it.
Import
import { Tooltip } from "@cocso-ui/react";Default
A tooltip that appears when hovering the trigger button.
"use client";
import { Button, Tooltip } from "@cocso-ui/react";
export default function TooltipDefault() {
return (
<div className="p-4">
<Tooltip.Provider>
<Tooltip>
<Tooltip.Trigger render={<Button variant="secondary" />}>
Hover me
</Tooltip.Trigger>
<Tooltip.Content>
This is a tooltip
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip>
</Tooltip.Provider>
</div>
);
}Positions
Use the
side prop on Tooltip.Content to control which side of the trigger the tooltip appears on."use client";
import { Button, Tooltip } from "@cocso-ui/react";
export default function TooltipPositions() {
return (
<div className="flex flex-wrap gap-3 p-4">
<Tooltip.Provider>
{(["top", "bottom", "left", "right"] as const).map((side) => (
<Tooltip key={side}>
<Tooltip.Trigger render={<Button variant="outline" />}>{side}</Tooltip.Trigger>
<Tooltip.Content side={side}>
Tooltip on {side}
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip>
))}
</Tooltip.Provider>
</div>
);
}API Reference
Tooltip.Provider
| Prop | Type | Default | Description |
|---|---|---|---|
delayDuration | number | 700 | Delay in milliseconds before the tooltip opens on hover. A shorter delay makes tooltips feel more responsive; a longer delay reduces visual noise. |
skipDelayDuration | number | 300 | Duration in milliseconds to skip the open delay when moving between nearby triggers. Enables fluid scanning of multiple tooltips. |
Tooltip (Root Container)
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | Controlled open state. Use together with `onOpenChange` for programmatic tooltip control. |
onOpenChange | (open: boolean) => void | - | Callback invoked when the tooltip should open or close. Receives the new boolean state. |
defaultOpen | boolean | false | Initial open state for uncontrolled usage. Rarely needed — tooltips are typically hover/focus-driven. |
Tooltip.Trigger
| Prop | Type | Default | Description |
|---|---|---|---|
render* | ReactElement | - | The element to render as the tooltip trigger. Receives hover/focus handlers and `aria-describedby` via prop merging. |
Tooltip.Content
| Prop | Type | Default | Description |
|---|---|---|---|
side | "top" | "bottom" | "left" | "right" | "top" | Preferred placement side relative to the trigger. Auto-flips if there is insufficient space on the preferred side. |
sideOffset | number | 4 | Distance in pixels between the trigger and the tooltip. |
align | "start" | "center" | "end" | "center" | Alignment of the tooltip along the trigger edge. |
alignOffset | number | 0 | Offset in pixels along the alignment axis for fine-tuning position. |
arrowPadding | number | 4 | Minimum distance in pixels between the arrow and the tooltip edge, preventing the arrow from overflowing corners. |
Tooltip.Arrow
| Prop | Type | Default | Description |
|---|---|---|---|
width | number | 10 | Width of the arrow caret in pixels. |
height | number | 5 | Height of the arrow caret in pixels. |