Skip to content

Commit c69a8b5

Browse files
committed
hide tooltip when new props received
1 parent 276629f commit c69a8b5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/components/TooltipPositioner.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ type Props = {
77

88
type State = {
99
offset: object,
10-
tooltipContainerInitialDimensions: object
10+
tooltipContainerInitialDimensions: object,
11+
tooltipContentArgsCurrent: object
1112
}
1213

1314
class TooltipPositioner extends React.Component<Props, State> {
1415
private containerRef = React.createRef<HTMLDivElement>()
1516

1617
state = {
1718
offset: null,
18-
tooltipContainerInitialDimensions: null
19+
tooltipContainerInitialDimensions: null,
20+
tooltipContentArgsCurrent: null
1921
}
2022

2123
// simple heuristics to check if the tooltip container exceeds the viewport
@@ -45,7 +47,8 @@ class TooltipPositioner extends React.Component<Props, State> {
4547

4648
this.setState({
4749
offset,
48-
tooltipContainerInitialDimensions
50+
tooltipContainerInitialDimensions,
51+
tooltipContentArgsCurrent: this.props.tooltipContentArgs
4952
})
5053
}
5154

@@ -59,7 +62,8 @@ class TooltipPositioner extends React.Component<Props, State> {
5962
// if new args, reset offset state
6063
if(pp.tooltipContentArgs !== this.props.tooltipContentArgs){
6164
this.setState({
62-
offset: null
65+
offset: null,
66+
tooltipContainerInitialDimensions: null
6367
})
6468
}
6569
else if(this.containerRef.current && !this.state.offset){
@@ -75,10 +79,11 @@ class TooltipPositioner extends React.Component<Props, State> {
7579

7680
const {
7781
offset,
78-
tooltipContainerInitialDimensions
82+
tooltipContainerInitialDimensions,
83+
tooltipContentArgsCurrent
7984
} = this.state
8085

81-
const containerStyle = offset?
86+
const containerStyle = offset && (tooltipContentArgsCurrent===tooltipContentArgs)?
8287
{
8388
transform: `translate(${offset.x}px,${offset.y}px)`
8489
} :
@@ -87,7 +92,7 @@ class TooltipPositioner extends React.Component<Props, State> {
8792
}
8893

8994
const tooltipContainerAttributes = {
90-
offset,
95+
offset: offset || {x:0, y:0},
9196
tooltipContainerInitialDimensions
9297
}
9398

0 commit comments

Comments
 (0)