메인 콘텐츠로 이동

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.Provider shares hover delay settings.
  • Supports side and align positioning props on Tooltip.Content.
  • Tooltip.Arrow renders 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.Provider to coordinate hover delays.

Accessibility

  • Tooltip content is exposed via role="tooltip" with the trigger linked via aria-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 Escape is 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

PropTypeDefaultDescription
delayDurationnumber700Delay in milliseconds before the tooltip opens on hover. A shorter delay makes tooltips feel more responsive; a longer delay reduces visual noise.
skipDelayDurationnumber300Duration in milliseconds to skip the open delay when moving between nearby triggers. Enables fluid scanning of multiple tooltips.

Tooltip (Root Container)

PropTypeDefaultDescription
openboolean-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.
defaultOpenbooleanfalseInitial open state for uncontrolled usage. Rarely needed — tooltips are typically hover/focus-driven.

Tooltip.Trigger

PropTypeDefaultDescription
render*ReactElement-The element to render as the tooltip trigger. Receives hover/focus handlers and `aria-describedby` via prop merging.

Tooltip.Content

PropTypeDefaultDescription
side"top" | "bottom" | "left" | "right""top"Preferred placement side relative to the trigger. Auto-flips if there is insufficient space on the preferred side.
sideOffsetnumber4Distance in pixels between the trigger and the tooltip.
align"start" | "center" | "end""center"Alignment of the tooltip along the trigger edge.
alignOffsetnumber0Offset in pixels along the alignment axis for fine-tuning position.
arrowPaddingnumber4Minimum distance in pixels between the arrow and the tooltip edge, preventing the arrow from overflowing corners.

Tooltip.Arrow

PropTypeDefaultDescription
widthnumber10Width of the arrow caret in pixels.
heightnumber5Height of the arrow caret in pixels.