@@ -7,15 +7,17 @@ type Props = {
7
7
8
8
type State = {
9
9
offset : object ,
10
- tooltipContainerInitialDimensions : object
10
+ tooltipContainerInitialDimensions : object ,
11
+ tooltipContentArgsCurrent : object
11
12
}
12
13
13
14
class TooltipPositioner extends React . Component < Props , State > {
14
15
private containerRef = React . createRef < HTMLDivElement > ( )
15
16
16
17
state = {
17
18
offset : null ,
18
- tooltipContainerInitialDimensions : null
19
+ tooltipContainerInitialDimensions : null ,
20
+ tooltipContentArgsCurrent : null
19
21
}
20
22
21
23
// simple heuristics to check if the tooltip container exceeds the viewport
@@ -45,7 +47,8 @@ class TooltipPositioner extends React.Component<Props, State> {
45
47
46
48
this . setState ( {
47
49
offset,
48
- tooltipContainerInitialDimensions
50
+ tooltipContainerInitialDimensions,
51
+ tooltipContentArgsCurrent : this . props . tooltipContentArgs
49
52
} )
50
53
}
51
54
@@ -59,7 +62,8 @@ class TooltipPositioner extends React.Component<Props, State> {
59
62
// if new args, reset offset state
60
63
if ( pp . tooltipContentArgs !== this . props . tooltipContentArgs ) {
61
64
this . setState ( {
62
- offset : null
65
+ offset : null ,
66
+ tooltipContainerInitialDimensions : null
63
67
} )
64
68
}
65
69
else if ( this . containerRef . current && ! this . state . offset ) {
@@ -75,10 +79,11 @@ class TooltipPositioner extends React.Component<Props, State> {
75
79
76
80
const {
77
81
offset,
78
- tooltipContainerInitialDimensions
82
+ tooltipContainerInitialDimensions,
83
+ tooltipContentArgsCurrent
79
84
} = this . state
80
85
81
- const containerStyle = offset ?
86
+ const containerStyle = offset && ( tooltipContentArgsCurrent === tooltipContentArgs ) ?
82
87
{
83
88
transform : `translate(${ offset . x } px,${ offset . y } px)`
84
89
} :
@@ -87,7 +92,7 @@ class TooltipPositioner extends React.Component<Props, State> {
87
92
}
88
93
89
94
const tooltipContainerAttributes = {
90
- offset,
95
+ offset : offset || { x : 0 , y : 0 } ,
91
96
tooltipContainerInitialDimensions
92
97
}
93
98
0 commit comments