Skip to content

Commit ebab740

Browse files
authored
fix: tooltip visibility issue on ios safari back navigation (#2068)
* fix: visibility issue on ios safari back navigation * fix: hello linter my old friend
1 parent 47ccd7d commit ebab740

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

packages/sage-react/lib/Tooltip/Tooltip.jsx

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Children, useState, cloneElement } from 'react';
1+
import React, { Children, useState, useEffect, cloneElement } from 'react';
22
import ReactDOM from 'react-dom';
33
import PropTypes from 'prop-types';
44
import { TooltipElement } from './TooltipElement';
@@ -23,24 +23,40 @@ export const Tooltip = ({
2323
setActive(false);
2424
}
2525

26+
// fix for Safari iOS back button issue
27+
useEffect(() => {
28+
const handlePageShow = () => {
29+
setActive(false);
30+
};
31+
32+
window.addEventListener('pageshow', handlePageShow);
33+
34+
return () => {
35+
window.removeEventListener('pageshow', handlePageShow);
36+
};
37+
}, []);
38+
2639
return (
2740
<>
28-
{Children.map(children, (child) => cloneElement(child, {
29-
onMouseEnter: handleActivate,
30-
onFocus: handleActivate,
31-
onMouseLeave: handleDeactivate,
32-
onBlur: handleDeactivate,
33-
...rest,
34-
}))}
35-
{active && ReactDOM.createPortal(
36-
<TooltipElement
37-
content={content}
38-
parentDomRect={parentDomRect}
39-
position={position}
40-
tooltipCustomClass={tooltipCustomClass}
41-
/>,
42-
document.body
41+
{Children.map(children, (child) =>
42+
cloneElement(child, {
43+
onMouseEnter: handleActivate,
44+
onFocus: handleActivate,
45+
onMouseLeave: handleDeactivate,
46+
onBlur: handleDeactivate,
47+
...rest,
48+
})
4349
)}
50+
{active
51+
&& ReactDOM.createPortal(
52+
<TooltipElement
53+
content={content}
54+
parentDomRect={parentDomRect}
55+
position={position}
56+
tooltipCustomClass={tooltipCustomClass}
57+
/>,
58+
document.body
59+
)}
4460
</>
4561
);
4662
};

0 commit comments

Comments
 (0)