Run the website in local development mode
masterStart a local development server using yarn start. This command opens a browser window and supports live reloading for most changes.
$ yarn startrepository·master·Indexed 26 days ago
https://github.com/reacttooltip/react-tooltipA React library used to display informative tooltips when users hover over or interact with specific elements. It supports custom HTML/React content via children, CSS selector-based targeting with the anchorSelect prop, and configurable event triggers such as openOnClick, openEvents, and closeEvents. Version 6.0.8.
Start a local development server using yarn start. This command opens a browser window and supports live reloading for most changes.
$ yarn startInstall the react-tooltip package using npm or yarn.
npm install react-tooltipyarn add react-tooltipBy default, tooltips disappear when the pointer leaves the anchor element. To allow users to interact with elements inside the tooltip (like buttons or inputs) or to satisfy WCAG 'hoverable' requirements, use the clickable prop on the <Tooltip /> component.
<a id="clickable">◕‿‿◕</a>
<Tooltip anchorSelect="#clickable" clickable>
<button>You can click me!</button>
</Tooltip>The type prop used in V4 for styling has been renamed to variant in V5.
Available values for variant are:
'dark''light''success''warning''error''info'You can apply the variant via the Tooltip component or directly on the anchor element using the data-tooltip-variant attribute.
import { Tooltip } from 'react-tooltip';
<a
data-tooltip-id="my-tooltip"
data-tooltip-content="Hello world!"
data-tooltip-variant="success"
>
◕‿‿◕
</a>
<Tooltip id="my-tooltip" />For versions v5.13.0 or newer, styles are injected into the page by default and no manual import is required.
If you are using a version older than v5.13.0, you must manually import the CSS file for the tooltip to appear. It is recommended to do this once in your src/index.js or equivalent entry point.
import 'react-tooltip/dist/react-tooltip.css'Generate static content for the website by running yarn build. The output will be placed in the build directory and can be hosted on any static content hosting service.
$ yarn buildTo style the tooltip using CSS classes, pass a string to the className prop.
Note on Specificity: Because react-tooltip uses default styles, you may need to increase your CSS specificity to override them without using !important. For example, instead of just .example, use .parent-class .example to ensure your rules take precedence.
If you need to style the tooltip arrow specifically, you can target the .example-arrow class within your custom class.
import { Tooltip } from 'react-tooltip'
<style>
.example {
color: #222;
background-color: rgb(0, 247, 255);
}
</style>
<div className="example-container">
<a
data-tooltip-id="my-tooltip-styles"
data-tooltip-content="Hello world!"
>
◕‿‿◕
</a>
<Tooltip id="my-tooltip-styles" className="example" />
</div>When upgrading from V4 to V5, note that the core implementation has changed from class components to a TypeScript-based implementation using floating-ui.
Tooltip instead of ReactTooltip. To maintain compatibility with existing codebases that use the name ReactTooltip, use: import { Tooltip as ReactTooltip } from 'react-tooltip'.data-tooltip-.data-for $\rightarrow$ data-tooltip-iddata-tip $\rightarrow$ data-tooltip-contentgetContent prop has been removed. Use the content prop for dynamic content, or the render prop for complex dynamic rendering.solid effect. To achieve the V4 effect="float" behavior, use the float prop.8px 21px to 8px 16px.The React Tooltip Scaling Benchmark is an automated harness used to compare the mount/unmount performance of V5 and V6 across various tooltip counts. You can run a single pass, a full statistical run, or aggregate existing results.
# Single benchmark pass (5 repeats per count)
node benchmarks/run-benchmark.mjs
# Full statistical run (100 passes across 5 workers, then aggregate)
yarn benchmark:scaling:full -r 100 -w 5
# Aggregate the latest N results
node benchmarks/aggregate-benchmarks.mjs --latest 100You can deploy the website using different methods depending on your access:
Using SSH:
$ USE_SSH=true yarn deployUsing GitHub Username (Non-SSH):
$ GIT_USER=<Your GitHub username> yarn deployIf you are using GitHub Pages for hosting, the yarn deploy command builds the website and pushes it to the gh-pages branch.
In V6, the data-tooltip-html attribute and the html prop have been removed. To display rich or multiline content, use one of the following methods:
children: Pass JSX directly as children to the Tooltip component. This is the preferred method for static rich content.render: Pass a function to the render prop that returns JSX. This is useful for dynamic content.Note: data-tooltip-content and the content prop remain supported for plain text strings.
// Using children for rich content
<a data-tooltip-id="my-tooltip">◕‿‿◕</a>
<Tooltip id="my-tooltip">
<div>
<h3>Cool stuff</h3>
<ul>
<li>This is cool</li>
</ul>
</div>
</Tooltip>
// Using render for rich content
<a data-tooltip-id="my-tooltip">◕‿‿◕</a>
<Tooltip
id="my-tooltip"
render={() => (
<div>
Hello
<br />
<b>rich</b> content
</div>
)}
/>You can trigger tooltips by adding specific data-tooltip-* attributes to your anchor elements.
Tooltip from react-tooltip.data-tooltip-id="<tooltip id>" and data-tooltip-content="<your text>" to your anchor elements.<Tooltip /> component and ensure its id matches the data-tooltip-id used on the anchors.import { Tooltip } from 'react-tooltip'
// 1. Anchor elements with data attributes
<a
data-tooltip-id="my-tooltip"
data-tooltip-content="Hello world!"
data-tooltip-place="top"
>
◕‿‿◕
</a>
// 2. The Tooltip element with matching ID
<Tooltip id="my-tooltip" />