Unkey
ComponentsTooltips

Tooltip

A flexible tooltip component with multiple positioning options, customizable content, and accessibility features for providing contextual information.

Overview

The Tooltip component provides a flexible way to display contextual information when users hover over or focus on elements. It's designed to offer multiple positioning options, customizable content, and comprehensive accessibility features for enhanced user experience.

Usage

import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@unkey/ui";
 
export default function MyComponent() {
  return (
    <TooltipProvider>
      <Tooltip>
        <TooltipTrigger asChild>
          <Button>Hover me</Button>
        </TooltipTrigger>
        <TooltipContent>
          <p>This is a helpful tooltip</p>
        </TooltipContent>
      </Tooltip>
    </TooltipProvider>
  );
}

Examples

On Hover

Examples showing different tooltip configurations and positioning options.

Features

  • Multiple Positions: Flexible positioning (top, bottom, left, right, and corners)
  • Customizable Content: Rich content support with text, icons, and components
  • Accessibility: Full accessibility support with proper ARIA attributes
  • Keyboard Navigation: Keyboard support for focus-based tooltips
  • Responsive Design: Adapts to different screen sizes and viewports
  • Dark Mode Support: Consistent appearance in light and dark themes
  • Customizable Styling: Extensive styling options through className props
  • Delay Control: Configurable show/hide delays for better UX

Props

TooltipProvider

PropTypeDefaultDescription
childrenReactNode-Tooltip components
delayDurationnumber700Delay before showing tooltip (ms)
skipDelayDurationnumber300Delay before hiding tooltip (ms)

Tooltip

PropTypeDefaultDescription
defaultOpenbooleanfalseWhether tooltip is open by default
openboolean-Controlled open state
onOpenChange(open: boolean) => void-Callback when open state changes
delayDurationnumber-Override delay duration
disableHoverableContentbooleanfalseDisable hover on tooltip content

TooltipTrigger

PropTypeDefaultDescription
asChildbooleanfalseWhether to render as child element
childrenReactNode-The trigger element

TooltipContent

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""top"Preferred side for tooltip
sideOffsetnumber4Distance from trigger element
align"start" | "center" | "end""center"Alignment relative to trigger
alignOffsetnumber0Offset from alignment
avoidCollisionsbooleantrueWhether to avoid viewport collisions
collisionBoundaryBoundary-Boundary for collision detection
collisionPaddingnumber | Padding0Padding for collision detection
arrowPaddingnumber0Padding for arrow positioning
sticky"partial" | "always""partial"Sticky behavior on collision
hideWhenDetachedbooleanfalseHide when trigger is detached
classNamestring-Additional CSS classes

Structure

The Tooltip system is composed of several components that work together:

  1. TooltipProvider - Context provider for tooltip management
  2. Tooltip - The root component that manages tooltip state
  3. TooltipTrigger - The element that triggers the tooltip
  4. TooltipContent - The actual tooltip content container

Styling

The component includes default styling with:

  • Consistent padding and border radius
  • Drop shadow for visual separation
  • Smooth animations for show/hide
  • Dark mode support with appropriate color schemes
  • Focus states for accessibility
  • Customizable through className props

Custom Styling

You can customize the appearance using className props:

<TooltipContent className="custom-tooltip-class">
  <p>Custom styled tooltip content</p>
</TooltipContent>

Accessibility

The Tooltip component is built with accessibility in mind:

  • ARIA Attributes: Proper ARIA labels and descriptions for screen readers
  • Keyboard Support: Full keyboard navigation and activation
  • Focus Management: Proper focus handling and announcements
  • Screen Reader Support: Announces tooltip content appropriately
  • High Contrast: Maintains proper contrast ratios
  • Semantic HTML: Uses appropriate HTML elements and roles

On this page