Tooltip
The Tooltip component displays short, contextual information when a user hovers over or focuses on an element. It is commonly used to explain icons, buttons, or UI elements without taking up permanent space.
Built with React Aria Components and styled using Tailwind CSS and the Tailgrids theme tokens.
Installation
Install the component using the Tailgrids CLI.
npx @tailgrids/cli@latest add tooltipAnatomy
The Tooltip component uses a compound pattern: TooltipTrigger wraps the trigger element and the Tooltip content.
import { Tooltip, TooltipTrigger } from "@/components/tailgrids/tooltip";
import { InfoCircle } from "@tailgrids/icons";
export default function TooltipUsageExample() {
return (
<TooltipTrigger>
<button className="text-primary">
<InfoCircle className="size-5" />
</button>
<Tooltip>Helpful context.</Tooltip>
</TooltipTrigger>
);
}Examples
Placements
The tooltip can be positioned with the placement prop: top, bottom, left, right and the start/end variants.
All Placements Example
Triggering with any Element
TooltipTrigger wraps its first child in React Aria's Focusable, so any focusable element (an icon button, a link, a custom component) can be used as the trigger.
Controlled Tooltip
Control the open state with isOpen and onOpenChange on TooltipTrigger.
The tooltip state is controlled by the parent.
API Reference
TooltipTrigger
The root. Manages the open state and provides Focusable + the trigger element.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The trigger element followed by the Tooltip content. |
delay | number | 0 | How long to wait before opening, in ms. |
isOpen | boolean | - | Controlled open state. |
defaultOpen | boolean | - | Uncontrolled default open state. |
onOpenChange | (isOpen: boolean) => void | - | Called when the open state changes. |
Tooltip
The popup containing the descriptive content.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The content to be displayed inside the tooltip. |
placement | Placement | "top" | The position relative to the trigger. |
offset | number | 8 | Distance between the trigger and the content. |
className | string | - | Additional CSS classes. |
Accessibility
- Uses
role="tooltip"for correct screen reader interpretation - Opens on hover and keyboard focus
- Closes automatically when focus or pointer leaves
- Fully keyboard accessible using the Tab key
- Screen readers announce tooltip content when the trigger is focused
