Gathering detailed insights and metrics for @evankennedy/react-popper-tooltip
Gathering detailed insights and metrics for @evankennedy/react-popper-tooltip
Gathering detailed insights and metrics for @evankennedy/react-popper-tooltip
Gathering detailed insights and metrics for @evankennedy/react-popper-tooltip
A React hook to effortlessly build smart tooltips.
npm install @evankennedy/react-popper-tooltip
Typescript
Module System
Node Version
NPM Version
Fix missing hover check in interactive mode
Updated on Jun 28, 2022
Fix unintentional dependency change
Updated on Jun 06, 2022
Add double click trigger, improve styles declaration, ability to change default tooltip text color
Updated on Jun 05, 2022
Add Shadow DOM support
Updated on May 25, 2021
Revert to mouseenter/mouseleave hover mechanic
Updated on Mar 15, 2021
Hover trigger bug fixes introduced in v4.1.0 🐛
Updated on Feb 23, 2021
TypeScript (84.17%)
CSS (10.7%)
JavaScript (4.65%)
Shell (0.49%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
250 Stars
251 Commits
57 Forks
3 Watchers
4 Branches
13 Contributors
Updated on Jan 22, 2025
Latest Version
3.1.0-react-17
Package Id
@evankennedy/react-popper-tooltip@3.1.0-react-17
Unpacked Size
103.13 kB
Size
17.34 kB
File Count
13
NPM Version
6.14.5
Node Version
12.18.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
29
React tooltip component based on react-popper, the React wrapper around popper.js library.
https://react-popper-tooltip.netlify.app
https://codesandbox.io/s/pykkz77z5j
1npm install react-popper-tooltip
or
1yarn add react-popper-tooltip
1import React from 'react';
2import {render} from 'react-dom';
3import TooltipTrigger from 'react-popper-tooltip';
4
5const Tooltip = ({
6 arrowRef,
7 tooltipRef,
8 getArrowProps,
9 getTooltipProps,
10 placement
11}) => (
12 <div
13 {...getTooltipProps({
14 ref: tooltipRef,
15 className: 'tooltip-container'
16 /* your props here */
17 })}
18 >
19 <div
20 {...getArrowProps({
21 ref: arrowRef,
22 className: 'tooltip-arrow',
23 'data-placement': placement
24 /* your props here */
25 })}
26 />
27 Hello, World!
28 </div>
29);
30
31const Trigger = ({getTriggerProps, triggerRef}) => (
32 <span
33 {...getTriggerProps({
34 ref: triggerRef,
35 className: 'trigger'
36 /* your props here */
37 })}
38 >
39 Click Me!
40 </span>
41);
42
43render(
44 <TooltipTrigger placement="right" trigger="click" tooltip={Tooltip}>
45 {Trigger}
46 </TooltipTrigger>,
47 document.getElementById('root')
48);
TooltipTrigger
is the only component exposed by the package. It's just a positioning engine. What to render is left completely to the user, which can be provided using render props. Your props should be passed through getTriggerProps
, getTooltipProps
and getArrowProps
.
Read more about render prop pattern if you're not familiar with this approach.
If you would like our opinionated container and arrow styles for your tooltip for quick start, you may import react-popper-tooltip/dist/styles.css
, and use the classes tooltip-container
and tooltip-arrow
as follows:
1import React from 'react'; 2import TooltipTrigger from 'react-popper-tooltip'; 3import 'react-popper-tooltip/dist/styles.css'; 4 5const Tooltip = ({children, tooltip, hideArrow, ...props}) => ( 6 <TooltipTrigger 7 {...props} 8 tooltip={({ 9 arrowRef, 10 tooltipRef, 11 getArrowProps, 12 getTooltipProps, 13 placement 14 }) => ( 15 <div 16 {...getTooltipProps({ 17 ref: tooltipRef, 18 className: 'tooltip-container' 19 })} 20 > 21 {!hideArrow && ( 22 <div 23 {...getArrowProps({ 24 ref: arrowRef, 25 className: 'tooltip-arrow', 26 'data-placement': placement 27 })} 28 /> 29 )} 30 {tooltip} 31 </div> 32 )} 33 > 34 {({getTriggerProps, triggerRef}) => ( 35 <span 36 {...getTriggerProps({ 37 ref: triggerRef, 38 className: 'trigger' 39 })} 40 > 41 {children} 42 </span> 43 )} 44 </TooltipTrigger> 45); 46 47export default Tooltip;
Then you can use it as shown in the example below.
1<Tooltip placement="top" trigger="click" tooltip="Hi there!"> 2 Click me 3</Tooltip>
To fiddle with our example recipes, run:
1> npm install 2> npm run docs
or
1> yarn 2> yarn docs
and open up localhost:3000 in your browser.
function({})
| required
This is called with an object. Read more about the properties of this object in the section "Children and tooltip functions".
function({})
| required
This is called with an object. Read more about the properties of this object in the section "Children and tooltip functions".
boolean
| defaults tofalse
This is the initial visibility state of the tooltip.
function(tooltipShown: boolean)
Called with the tooltip state, when the visibility of the tooltip changes
boolean
| control prop
Use this prop if you want to control the visibility state of the tooltip.
react-popper-tooltip
manages its own state internally. You can use this prop to pass the
visibility state of the tooltip from the outside. You will be required to keep this state up to
date (this is where onVisibilityChange
becomes useful), but you can also control the state
from anywhere, be that state from other components, redux
, react-router
, or anywhere else.
number
| defaults to0
Delay in showing the tooltip (ms).
number
| defaults to0
Delay in hiding the tooltip (ms).
string
| defaults toright
The tooltip placement. Valid placements are:
auto
top
right
bottom
left
Each placement can have a variation from this list:
-start
-end
string
orstring[]
| defaults to"hover"
The event(s) that trigger the tooltip. One of click
, right-click
, hover
, focus
, and none
, or an array of them.
function(HTMLElement) => void
Function that can be used to obtain a trigger element reference.
boolean
| defaults totrue
Whether to close the tooltip when its trigger is out of boundary.
boolean
| defaults totrue
Whether to use React.createPortal
for creating tooltip.
HTMLElement
| defaults todocument.body
Element to be used as portal container
boolean
| defaults tofalse
Whether to spawn the tooltip at the cursor position.
Recommended usage with hover trigger and no arrow element
array
| defaults to []
Modifiers passed directly to the underlying popper.js instance. For more information, refer to Popper.js’ modifier docs.
object
Options to MutationObserver
, used internally for updating tooltip position based on its DOM changes.
For more information, refer to MutationObserver docs.
Default options:
{
childList: true,
subtree: true
}
This is where you render whatever you want. react-popper-tooltip
uses two render props children
and tooltip
. Children
prop is used to trigger the appearance of the tooltip and tooltip
displays the tooltip itself.
You use it like so:
1const tooltip = ( 2 <TooltipTrigger tooltip={tooltip => <div>{/* more jsx here */}</div>}> 3 {trigger => <div>{/* more jsx here */}</div>} 4 </TooltipTrigger> 5);
These functions are used to apply props to the elements that you render.
It's advisable to pass all your props to that function rather than applying them on the element
yourself to avoid your props being overridden (or overriding the props returned). For example
<button {...getTriggerProps({onClick: event => console.log(event))}>Click me</button>
property | type | description |
---|---|---|
triggerRef | function ref | returns the react ref you should apply to the trigger element. |
getTriggerProps | function({}) | returns the props you should apply to the trigger element you render. |
property | type | description |
---|---|---|
arrowRef | function ref | return the react ref you should apply to the tooltip arrow element. |
tooltipRef | function ref | return the react ref you should apply to the tooltip element. |
getArrowProps | function({}) | return the props you should apply to the tooltip arrow element. |
getTooltipProps | function({}) | returns the props you should apply to the tooltip element you render. |
placement | string | return the dynamic placement of the tooltip. |
This library is based on react-popper, the official react wrapper around Popper.js.
Using of render props, prop getters and doc style of this library are heavily inspired by downshift.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
48 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More