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 tooltip

Anatomy

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.

State: false

API Reference

TooltipTrigger

The root. Manages the open state and provides Focusable + the trigger element.

PropTypeDefaultDescription
childrenReact.ReactNode-The trigger element followed by the Tooltip content.
delaynumber0How long to wait before opening, in ms.
isOpenboolean-Controlled open state.
defaultOpenboolean-Uncontrolled default open state.
onOpenChange(isOpen: boolean) => void-Called when the open state changes.

Tooltip

The popup containing the descriptive content.

PropTypeDefaultDescription
childrenReact.ReactNode-The content to be displayed inside the tooltip.
placementPlacement"top"The position relative to the trigger.
offsetnumber8Distance between the trigger and the content.
classNamestring-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