React Tooltip Component
The `rc-tooltip` package provides a highly customizable and unstyled React tooltip component, focusing on core functionality like positioning, event triggers, and state management. It allows developers to integrate robust tooltip behavior while maintaining full control over the visual presentation, aligning with a 'bring your own UI' philosophy. The version requested, 6.4.0, was the last major release under the `rc-tooltip` package name. However, active development and new features for this component have transitioned to the `@rc-component/tooltip` package, currently at version 1.x.x. While `rc-tooltip` 6.4.0 remains functional for its intended purpose, it is effectively superseded, and new projects or those requiring ongoing updates and accessibility enhancements should migrate to the `@rc-component/tooltip` package. The original `rc-tooltip` package's last update was approximately three years ago.
Common errors
-
Error: Can't resolve 'rc-tooltip' or 'rc-tooltip/assets/bootstrap.css'
cause The package or its default styles are not installed or cannot be found by the module resolver.fixEnsure `rc-tooltip` is installed: `npm install rc-tooltip` or `yarn add rc-tooltip`. Verify the import path for CSS is correct. -
TypeError: Cannot read properties of undefined (reading 'call') at Tooltip
cause This often indicates `react` or `react-dom` peer dependencies are missing or their versions are incompatible.fixInstall React and ReactDOM if not present: `npm install react react-dom` or `yarn add react react-dom`. Check the peer dependency requirements in your `package.json` for `rc-tooltip`. -
Tooltip does not appear on hover/focus.
cause Common causes include an incorrect `trigger` prop, missing `overlay` content, or CSS conflicts (e.g., z-index issues) preventing the tooltip from being visible.fixVerify that the `trigger` prop is correctly set (e.g., `['hover', 'focus']`). Ensure the `overlay` prop has valid React content. Inspect CSS for z-index conflicts or hidden overflow on parent elements.
Warnings
- breaking The `rc-tooltip` package has been effectively renamed to `@rc-component/tooltip`. New development, features, and significant bug fixes are now applied to the new package. Users should migrate to `@rc-component/tooltip` for a actively maintained version.
- gotcha The `rc-tooltip` package, specifically version 6.x, is no longer actively maintained under this name. This means new browser compatibility issues, security vulnerabilities, or accessibility improvements present in modern web standards may not be addressed.
- deprecated Using `require('rc-tooltip')` directly in an ESM project without proper transpilation can lead to issues with default exports being nested under a `.default` property.
Install
-
npm install rc-tooltip -
yarn add rc-tooltip -
pnpm add rc-tooltip
Imports
- Tooltip
import { Tooltip } from 'rc-tooltip';import Tooltip from 'rc-tooltip';
- ITooltipProps
import type { ITooltipProps } from 'rc-tooltip'; - Tooltip (CJS)
const { Tooltip } = require('rc-tooltip');const Tooltip = require('rc-tooltip');
Quickstart
import React from 'react';
import ReactDOM from 'react-dom/client';
import Tooltip from 'rc-tooltip';
import 'rc-tooltip/assets/bootstrap.css'; // Or your custom styles
const App = () => (
<div style={{ margin: 100, display: 'flex', justifyContent: 'center' }}>
<Tooltip
placement="right"
overlay={<span>Tooltip Content</span>}
trigger={['hover', 'focus']}
mouseEnterDelay={0.1}
mouseLeaveDelay={0.1}
destroyTooltipOnHide={true}
>
<button type="button" style={{ padding: '10px 20px', cursor: 'pointer' }}>
Hover Me for Tooltip
</button>
</Tooltip>
</div>
);
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(<App />);