React tooltip component library with customizable positioning, styling, and accessibility features
npx @tessl/cli install tessl/npm-react-tooltip@5.29.0React Tooltip is a modern, accessible tooltip component library for React applications that provides comprehensive tooltip functionality with customizable positioning, styling, and behavior. Built with TypeScript and powered by Floating UI for advanced positioning algorithms, it offers automatic placement adjustment to avoid viewport edges, supports multiple trigger events (hover, click, focus), and includes accessibility features like ARIA attributes and keyboard navigation.
npm install react-tooltipimport { Tooltip } from "react-tooltip";For CommonJS:
const { Tooltip } = require("react-tooltip");Additional imports for advanced usage:
import {
Tooltip,
TooltipProvider,
TooltipWrapper,
removeStyle,
type ITooltip,
type PlacesType,
type VariantType
} from "react-tooltip";import { Tooltip } from "react-tooltip";
function App() {
return (
<div>
{/* Element with tooltip */}
<button
data-tooltip-id="my-tooltip"
data-tooltip-content="Hello world!"
>
Hover me
</button>
{/* Tooltip component */}
<Tooltip id="my-tooltip" />
</div>
);
}For versions before 5.13.0, you must import the CSS file:
import 'react-tooltip/dist/react-tooltip.css'React Tooltip is built around several key components:
Tooltip component providing full tooltip functionalityPrimary tooltip component with comprehensive configuration options, imperative API, and accessibility features. Supports declarative usage via data attributes and programmatic control via ref methods.
function Tooltip(props: ITooltipController): React.ReactElement;Provider and wrapper components for backward compatibility with earlier versions. These components are deprecated in favor of the main Tooltip component and data attributes.
function TooltipProvider(props: { children: React.ReactNode }): React.ReactElement;
function TooltipWrapper(props: ITooltipWrapper): React.ReactElement;Utility functions for managing tooltip styles and CSS injection. Includes functions for removing injected styles and configuring style behavior.
function removeStyle(options?: { type?: 'core' | 'base'; id?: string }): void;type PlacesType =
| 'top' | 'top-start' | 'top-end'
| 'right' | 'right-start' | 'right-end'
| 'bottom' | 'bottom-start' | 'bottom-end'
| 'left' | 'left-start' | 'left-end';
type VariantType = 'dark' | 'light' | 'success' | 'warning' | 'error' | 'info';
type PositionStrategy = 'absolute' | 'fixed';
type EventsType = 'hover' | 'click';
interface IPosition {
x: number;
y: number;
}
interface TooltipRefProps {
open: (options?: TooltipImperativeOpenOptions) => void;
close: (options?: TooltipImperativeCloseOptions) => void;
readonly activeAnchor: HTMLElement | null;
readonly place: PlacesType;
readonly isOpen: boolean;
}
interface TooltipImperativeOpenOptions {
anchorSelect?: string;
position?: IPosition;
place?: PlacesType;
content?: ChildrenType;
delay?: number;
}
interface TooltipImperativeCloseOptions {
delay?: number;
}