Skip to content

Commit 8d20f32

Browse files
chore: merge from master
2 parents 1f29dda + be19fd1 commit 8d20f32

File tree

15 files changed

+272
-159
lines changed

15 files changed

+272
-159
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ If applicable, add screenshots to help explain your problem.
2626
- OS: [e.g. iOS]
2727
- Browser [e.g. chrome, safari]
2828
- Version [e.g. 22]
29+
- Frameworks [e.g. React 18, Next.js 13]
2930

3031
**Smartphone (please complete the following information if possible or delete this section):**
3132
- Device: [e.g. iPhone6]
3233
- OS: [e.g. iOS8.1]
3334
- Browser [e.g. stock browser, safari]
3435
- Version [e.g. 22]
36+
- Frameworks [e.g. React 18, Next.js 13]
3537

3638
**Additional context**
3739
Add any other context about the problem here.

.github/workflows/pull-request.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ on:
55
branches:
66
- '!master'
77
pull_request:
8+
types: [opened, synchronize, reopened, ready_for_review]
89

910
jobs:
1011
lint:
12+
if: 'github.event.pull_request.draft == false'
1113
uses: ./.github/workflows/lint.yaml
1214

1315
bundlesize:
16+
if: 'github.event.pull_request.draft == false'
1417
uses: ./.github/workflows/bundlesize.yaml
18+
19+
fail_if_pull_request_is_draft:
20+
if: github.event.pull_request.draft == true
21+
runs-on: ubuntu-18.04
22+
steps:
23+
- name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass.
24+
run: exit 1

.npmignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ coverage/
2121
.travis.yml
2222
.editorconfig
2323

24-
// others
24+
// misc folders
2525
.vscode/
2626
.husky/
2727
.github/
28+
29+
// misc files
30+
bundlesize.config.json
31+
32+
// bundler - rollup
33+
rollup.config.dev.js
34+
rollup.config.prod.js
35+
rollup.config.types.js

bundlesize.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"files": [
33
{
44
"path": "./dist/react-tooltip.cjs.min.js",
5-
"maxSize": "13.5 kB"
5+
"maxSize": "14 kB"
66
},
77
{
88
"path": "./dist/react-tooltip.esm.min.js",
9-
"maxSize": "13.5 kB"
9+
"maxSize": "14 kB"
1010
},
1111
{
1212
"path": "./dist/react-tooltip.umd.min.js",
13-
"maxSize": "13.5 kB"
13+
"maxSize": "14 kB"
1414
}
1515
]
1616
}

docs/docs/options.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,3 @@ import 'react-tooltip/dist/react-tooltip.css';
109109
| data-tooltip-show | number | false | | any `number` | tooltip show will be delayed in miliseconds by the amount of value |
110110
| data-tooltip-hide | number | false | | any `number` | tooltip hide will be delayed in miliseconds by the amount of value |
111111
| data-tooltip-float | boolean | false | `false` | `true` `false` | tooltip will follow the mouse position when it moves inside the anchor element (same as V4's `effect="float"`) |
112-
113-
#### Observations
114-
115-
- When using `data-tooltip-content` the `<br />` works by default
116-
- When using prop `content` the `<br />` doesn't work by default, use prop `html` instead of this

docs/docs/upgrade-guide/changelog-v4-v5.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ If you are using V4 and want to use V5, please read this doc.
88

99
## From V4 to V5
1010

11-
V4 was a great react tooltip component but was built a few years ago, he was built with react class components and it's hard to maintain and to the community give contributions, so, with this in mind, we build a new version of react tooltip using [floating-ui](https://floating-ui.com/) behind the scenes. This gives a great improvement in performance and in a new and easier code to let the community contribute to the project.
11+
V4 was a great react tooltip component but was built a few years ago, it was built with react class components and it's hard to maintain and to the community give contributions, so, with this in mind, we built a new version of react tooltip using [floating-ui](https://floating-ui.com/) behind the scenes. This gives a great improvement in performance and a new and easier code to let the community contribute to the project.
1212

1313
## Improvements
1414

@@ -22,7 +22,7 @@ V4 was a great react tooltip component but was built a few years ago, he was bui
2222
- All data attributes are now prefixed with `data-tooltip-`
2323
- Default Padding changed from `padding: 8px 21px;` to `padding: 8px 16px;`
2424
- Exported module now is `Tooltip` instead of `ReactTooltip`
25-
- - If you already have a `Tooltip` component in your application and want to explicitly declare this is `ReactTooltip`, just `import { Tooltip as ReactTooltip } from "react-tooltip"`
25+
- If you already have a `Tooltip` component in your application and want to explicitly declare this as `ReactTooltip`, just `import { Tooltip as ReactTooltip } from "react-tooltip"`
2626
- CSS import is now optional, so you can modify and/or add any styling to your floating tooltip element
2727
- `data-tip` attribute now is `data-tooltip-content`
2828
- `getContent` prop was removed. Instead, you can directly pass dynamic content to the `content` tooltip prop, or to `data-tooltip-content` in the anchor element

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"raw-loader": "^4.0.2",
2424
"react": "18.2.0",
2525
"react-dom": "18.2.0",
26-
"react-tooltip": "5.7.3"
26+
"react-tooltip": "5.7.5"
2727
},
2828
"devDependencies": {
2929
"@docusaurus/module-type-aliases": "2.3.0",

docs/yarn.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,17 +1605,17 @@
16051605
url-loader "^4.1.1"
16061606
webpack "^5.73.0"
16071607

1608-
"@floating-ui/core@^1.0.2":
1609-
version "1.0.2"
1610-
resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.0.2.tgz#d06a66d3ad8214186eda2432ac8b8d81868a571f"
1611-
integrity sha512-Skfy0YS3NJ5nV9us0uuPN0HDk1Q4edljaOhRBJGDWs9EBa7ZVMYBHRFlhLvvmwEoaIM9BlH6QJFn9/uZg0bACg==
1608+
"@floating-ui/core@^1.1.0":
1609+
version "1.2.0"
1610+
resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.2.0.tgz#ae7ae7923d41f3d84cb2fd88740a89436610bbec"
1611+
integrity sha512-GHUXPEhMEmTpnpIfesFA2KAoMJPb1SPQw964tToQwt+BbGXdhqTCWT1rOb0VURGylsxsYxiGMnseJ3IlclVpVA==
16121612

1613-
"@floating-ui/dom@^1.0.4":
1614-
version "1.0.7"
1615-
resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.0.7.tgz#9e8e6615ce03e5ebc6a4ae879640a199a366f86d"
1616-
integrity sha512-6RsqvCYe0AYWtsGvuWqCm7mZytnXAZCjWtsWu1Kg8dI3INvj/DbKlDsZO+mKSaQdPT12uxIW9W2dAWJkPx4Y5g==
1613+
"@floating-ui/dom@1.1.1":
1614+
version "1.1.1"
1615+
resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.1.1.tgz#66aa747e15894910869bf9144fc54fc7d6e9f975"
1616+
integrity sha512-TpIO93+DIujg3g7SykEAGZMDtbJRrmnYRCNYSjJlvIbGhBjRSNTLVbNeDQBrzy9qDgUbiWdc7KA0uZHZ2tJmiw==
16171617
dependencies:
1618-
"@floating-ui/core" "^1.0.2"
1618+
"@floating-ui/core" "^1.1.0"
16191619

16201620
"@hapi/hoek@^9.0.0":
16211621
version "9.3.0"
@@ -6125,12 +6125,12 @@ react-textarea-autosize@^8.3.2:
61256125
use-composed-ref "^1.3.0"
61266126
use-latest "^1.2.1"
61276127

6128-
react-tooltip@5.7.3:
6129-
version "5.7.3"
6130-
resolved "https://registry.yarnpkg.com/react-tooltip/-/react-tooltip-5.7.3.tgz#41971e34d37ba0fdca530b3327915eba96a487c8"
6131-
integrity sha512-aaGMRQKSpsixwekVtL268D2f4mJAw4PTTEAziyjYhalm8YmFkPoZKQDnVInjmBAmcLWmY7o+yJU5SHB3rcC7Tg==
6128+
react-tooltip@5.7.5:
6129+
version "5.7.5"
6130+
resolved "https://registry.yarnpkg.com/react-tooltip/-/react-tooltip-5.7.5.tgz#f3487e000a24b6ff84c8181064809a57b43c2e99"
6131+
integrity sha512-hAr3AMSF47AuycEnI+ShwloYHTtVrftocXCfEjWAFvvAVpNGE9wredZs6NlUE1JtpOXIOe/oJUpoYj925v5hLQ==
61326132
dependencies:
6133-
"@floating-ui/dom" "^1.0.4"
6133+
"@floating-ui/dom" "1.1.1"
61346134
classnames "^2.3.2"
61356135

61366136
react@18.2.0:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tooltip",
3-
"version": "5.7.3",
3+
"version": "5.7.5",
44
"description": "react tooltip component",
55
"scripts": {
66
"dev": "node ./cli.js --env=development && node --max_old_space_size=2048 ./node_modules/rollup/dist/bin/rollup -c rollup.config.dev.js --watch",
@@ -117,7 +117,7 @@
117117
]
118118
},
119119
"dependencies": {
120-
"@floating-ui/dom": "^1.0.4",
120+
"@floating-ui/dom": "1.1.1",
121121
"classnames": "^2.3.2"
122122
}
123123
}

src/components/Tooltip/Tooltip.tsx

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Tooltip = ({
2020
events = ['hover'],
2121
positionStrategy = 'absolute',
2222
middlewares,
23-
wrapper: WrapperElement = 'div',
23+
wrapper: WrapperElement,
2424
children = null,
2525
delayShow = 0,
2626
delayHide = 0,
@@ -41,12 +41,13 @@ const Tooltip = ({
4141
setActiveAnchor,
4242
}: ITooltip) => {
4343
const tooltipRef = useRef<HTMLElement>(null)
44-
const tooltipArrowRef = useRef<HTMLDivElement>(null)
44+
const tooltipArrowRef = useRef<HTMLElement>(null)
4545
const tooltipShowDelayTimerRef = useRef<NodeJS.Timeout | null>(null)
4646
const tooltipHideDelayTimerRef = useRef<NodeJS.Timeout | null>(null)
4747
const [inlineStyles, setInlineStyles] = useState({})
4848
const [inlineArrowStyles, setInlineArrowStyles] = useState({})
4949
const [show, setShow] = useState(false)
50+
const [rendered, setRendered] = useState(false)
5051
const wasShowing = useRef(false)
5152
const lastFloatPosition = useRef<IPosition | null>(null)
5253
/**
@@ -73,14 +74,44 @@ const Tooltip = ({
7374
}
7475
}, [anchorSelect])
7576

76-
const handleShow = (value: boolean) => {
77-
if (setIsOpen) {
78-
setIsOpen(value)
77+
useEffect(() => {
78+
if (!show) {
79+
setRendered(false)
7980
}
81+
}, [show])
82+
83+
const handleShow = (value: boolean) => {
84+
setRendered(true)
85+
/**
86+
* wait for the component to render and calculate position
87+
* before actually showing
88+
*/
89+
setTimeout(() => {
90+
setIsOpen?.(value)
91+
if (isOpen === undefined) {
92+
setShow(value)
93+
}
94+
}, 10)
95+
}
96+
97+
/**
98+
* this replicates the effect from `handleShow()`
99+
* when `isOpen` is changed from outside
100+
*/
101+
useEffect(() => {
80102
if (isOpen === undefined) {
81-
setShow(value)
103+
return () => null
82104
}
83-
}
105+
if (isOpen) {
106+
setRendered(true)
107+
}
108+
const timeout = setTimeout(() => {
109+
setShow(isOpen)
110+
}, 10)
111+
return () => {
112+
clearTimeout(timeout)
113+
}
114+
}, [isOpen])
84115

85116
useEffect(() => {
86117
if (show === wasShowing.current) {
@@ -138,7 +169,7 @@ const Tooltip = ({
138169
const handleHideTooltip = () => {
139170
if (clickable) {
140171
// allow time for the mouse to reach the tooltip, in case there's a gap
141-
handleHideTooltipDelayed(delayHide || 50)
172+
handleHideTooltipDelayed(delayHide || 100)
142173
} else if (delayHide) {
143174
handleHideTooltipDelayed()
144175
} else {
@@ -330,7 +361,12 @@ const Tooltip = ({
330361
})
331362
parentObserver.disconnect()
332363
}
364+
/**
365+
* rendered is also a dependency to ensure anchor observers are re-registered
366+
* since `tooltipRef` becomes stale after removing/adding the tooltip to the DOM
367+
*/
333368
}, [
369+
rendered,
334370
anchorRefs,
335371
activeAnchor,
336372
closeOnEsc,
@@ -389,7 +425,6 @@ const Tooltip = ({
389425
}
390426
}, [
391427
show,
392-
isOpen,
393428
anchorId,
394429
anchorsBySelect,
395430
activeAnchor,
@@ -426,13 +461,14 @@ const Tooltip = ({
426461
}, [])
427462

428463
const hasContentOrChildren = Boolean(html || content || children)
464+
const canShow = hasContentOrChildren && show && Object.keys(inlineStyles).length > 0
429465

430-
return (
466+
return rendered ? (
431467
<WrapperElement
432468
id={id}
433469
role="tooltip"
434470
className={classNames('react-tooltip', styles['tooltip'], styles[variant], className, {
435-
[styles['show']]: hasContentOrChildren && (isOpen || show),
471+
[styles['show']]: canShow,
436472
[styles['fixed']]: positionStrategy === 'fixed',
437473
[styles['clickable']]: clickable,
438474
})}
@@ -452,7 +488,7 @@ const Tooltip = ({
452488
ref={tooltipArrowRef}
453489
/>
454490
</WrapperElement>
455-
)
491+
) : null
456492
}
457493

458494
export default Tooltip

0 commit comments

Comments
 (0)