Skip to content

Commit 671005d

Browse files
Merge branch 'master' into feat/imperative-mode
2 parents 7bd996d + 497942c commit 671005d

File tree

6 files changed

+112
-6
lines changed

6 files changed

+112
-6
lines changed

docs/docs/examples/styling.mdx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ import { Tooltip } from 'react-tooltip'
212212

213213
#### Tooltip Arrow with a different color from Tooltip
214214

215+
:::info
216+
217+
This is for demonstration purposes only. Using `arrowColor` instead is recommended.
218+
219+
```jsx
220+
<Tooltip arrowColor="red" />
221+
```
222+
223+
:::
224+
215225
```jsx
216226
import { Tooltip } from 'react-tooltip'
217227

@@ -244,6 +254,38 @@ import { Tooltip } from 'react-tooltip'
244254
<Tooltip id="my-tooltip-diff" className="example-diff-arrow" classNameArrow="example-arrow" />
245255
</div>
246256

257+
### Changing the opacity
258+
259+
Setting the opacity through CSS directly on the tooltip element breaks functionality. Use the `opacity` prop, or override the `--rt-opacity` CSS variable instead.
260+
261+
```jsx
262+
import { Tooltip } from 'react-tooltip'
263+
264+
<div className="example-container">
265+
<a data-tooltip-id="my-tooltip-opacity" data-tooltip-content="Hello world!">
266+
◕‿‿◕
267+
</a>
268+
<Tooltip id="my-tooltip-opacity" opacity={0.3} />
269+
</div>
270+
```
271+
272+
```css
273+
/* To be used instead of the `opacity` prop, not required otherwise */
274+
:root {
275+
--rt-opacity: 0.3;
276+
}
277+
```
278+
279+
<div
280+
className="example-container"
281+
style={{ display: 'flex', columnGap: '16px', justifyContent: 'center' }}
282+
>
283+
<TooltipAnchor data-tooltip-id="my-tooltip-opacity" data-tooltip-content="Hello world!">
284+
◕‿‿◕
285+
</TooltipAnchor>
286+
<Tooltip id="my-tooltip-opacity" opacity={0.3} />
287+
</div>
288+
247289
### Changing the border radius
248290

249291
#### Removing radius
@@ -364,6 +406,33 @@ import { Tooltip } from 'react-tooltip'
364406
<Tooltip id="my-tooltip-padding" className="example-padding" />
365407
</div>
366408

409+
### Changing the border
410+
411+
If you're using the tooltip with the arrow, setting a border through CSS will not work for the arrow.
412+
413+
We recommend using the `border` prop to avoid that.
414+
415+
```jsx
416+
import { Tooltip } from 'react-tooltip'
417+
418+
<div className="example-container">
419+
<a data-tooltip-id="my-tooltip-border" data-tooltip-content="Hello world!">
420+
◕‿‿◕
421+
</a>
422+
<Tooltip id="my-tooltip-border" border="1px solid red" />
423+
</div>
424+
```
425+
426+
<div
427+
className="example-container"
428+
style={{ display: 'flex', columnGap: '16px', justifyContent: 'center' }}
429+
>
430+
<TooltipAnchor data-tooltip-id="my-tooltip-border" data-tooltip-content="Hello world!">
431+
◕‿‿◕
432+
</TooltipAnchor>
433+
<Tooltip id="my-tooltip-border" border="1px solid red" />
434+
</div>
435+
367436
---
368437

369438
:::info

docs/docs/troubleshooting.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ If you've imported the default styling and the tooltip is still not showing up w
6464

6565
If `data-tooltip-content` and `data-tooltip-html` are both unset (or they have empty values) on the anchor element, and also the `content`, `render`, and `children` props on the tooltip are unset (or have empty values), the tooltip is not shown by default.
6666

67+
## The tooltip doesn't close
68+
69+
This usually happens when you try to set the tooltip opacity via CSS. Due to the opacity being used internally to control the tooltip state, overriding it breaks functionality.
70+
71+
Instead, use the `opacity` prop, or override the `--rt-opacity` CSS variable. See [the examples](./examples/styling#changing-the-opacity) for more details.
72+
73+
```jsx
74+
<Tooltip opacity={1} />
75+
```
76+
77+
or
78+
79+
```css
80+
:root {
81+
--rt-opacity: 1;
82+
}
83+
```
84+
85+
## The border doesn't show for the arrow
86+
87+
Simply setting the border for the tooltip through CSS will not work for the arrow.
88+
89+
Instead, use [the `border` prop](./examples/styling#changing-the-border).
90+
91+
```jsx
92+
<Tooltip border="1px solid red" />
93+
```
94+
6795
## Bad performance
6896

6997
If you're experiencing any kind of unexpected behavior or bad performance on your application when using ReactTooltip, here are a few things you can try.

src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ function App() {
103103
ref={tooltipRef}
104104
anchorSelect="section[id='section-anchor-select'] > p > button"
105105
place="bottom"
106-
imperativeModeOnly
106+
openEvents={{ click: true }}
107+
closeEvents={{ click: true }}
108+
globalCloseEvents={{ clickOutsideAnchor: true }}
107109
>
108110
Tooltip content
109111
</Tooltip>

src/components/Tooltip/Tooltip.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ const Tooltip = ({
751751
}, [id, anchorSelect, imperativeOptions?.anchorSelect])
752752

753753
const actualContent = imperativeOptions?.content ?? content
754-
const canShow = Boolean(!hidden && actualContent && show && Object.keys(inlineStyles).length > 0)
754+
const canShow = show && Object.keys(inlineStyles).length > 0
755755

756756
useImperativeHandle(forwardRef, () => ({
757757
open: (options) => {
@@ -782,10 +782,10 @@ const Tooltip = ({
782782
},
783783
activeAnchor,
784784
place: actualPlacement,
785-
isOpen: rendered && canShow,
785+
isOpen: rendered && !hidden && actualContent && canShow,
786786
}))
787787

788-
return rendered ? (
788+
return rendered && !hidden && actualContent ? (
789789
<WrapperElement
790790
id={id}
791791
role="tooltip"

src/components/TooltipController/TooltipController.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
} from 'components/Tooltip/TooltipTypes'
1414
import { useTooltip } from 'components/TooltipProvider'
1515
import { TooltipContent } from 'components/TooltipContent'
16+
import cssSupports from 'utils/css-supports'
1617
import type { ITooltipController } from './TooltipControllerTypes'
1718

1819
const TooltipController = React.forwardRef<TooltipImperativeProps, ITooltipController>(
@@ -280,15 +281,15 @@ const TooltipController = React.forwardRef<TooltipImperativeProps, ITooltipContr
280281
// eslint-disable-next-line no-console
281282
console.warn('[react-tooltip] Do not set `style.border`. Use `border` prop instead.')
282283
}
283-
if (border && !CSS.supports('border', `${border}`)) {
284+
if (border && !cssSupports('border', `${border}`)) {
284285
// eslint-disable-next-line no-console
285286
console.warn(`[react-tooltip] "${border}" is not a valid \`border\`.`)
286287
}
287288
if (style?.opacity) {
288289
// eslint-disable-next-line no-console
289290
console.warn('[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead.')
290291
}
291-
if (opacity && !CSS.supports('opacity', `${opacity}`)) {
292+
if (opacity && !cssSupports('opacity', `${opacity}`)) {
292293
// eslint-disable-next-line no-console
293294
console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`)
294295
}

src/utils/css-supports.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const cssSupports = (property: string, value: string): boolean => {
2+
const hasCssSupports = 'CSS' in window && 'supports' in window.CSS
3+
return hasCssSupports ? window.CSS.supports(property, value) : true
4+
}
5+
6+
export default cssSupports

0 commit comments

Comments
 (0)