From a9fdedbeae6fb81aa0291768ff28ebe91be2ed5e Mon Sep 17 00:00:00 2001 From: trisianto Date: Sun, 27 Oct 2019 13:29:01 -0700 Subject: [PATCH 1/2] fixed init state key --- src/components/TooltipPositioner.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/TooltipPositioner.tsx b/src/components/TooltipPositioner.tsx index df1fff98..a722fc52 100644 --- a/src/components/TooltipPositioner.tsx +++ b/src/components/TooltipPositioner.tsx @@ -9,7 +9,8 @@ class TooltipPositioner extends React.Component { private containerRef = React.createRef() state = { - offset: null + offset: null, + tooltipContainerInitialDimensions: null } // simple heuristics to check if the tooltip container exceeds the viewport @@ -19,7 +20,8 @@ class TooltipPositioner extends React.Component { x: 0, y: 0 } - const { right, left, top, bottom } = this.containerRef.current.getBoundingClientRect() + const tooltipContainerInitialDimensions = this.containerRef.current.getBoundingClientRect() + const { right, left, top, bottom } = tooltipContainerInitialDimensions const containerWidth = right - left const containerHeight = bottom - top @@ -37,7 +39,8 @@ class TooltipPositioner extends React.Component { } this.setState({ - offset + offset, + tooltipContainerInitialDimensions }) } @@ -66,7 +69,8 @@ class TooltipPositioner extends React.Component { } = this.props const { - offset + offset, + tooltipContainerInitialDimensions } = this.state const containerStyle = offset? @@ -77,10 +81,15 @@ class TooltipPositioner extends React.Component { opacity: 0 } + const tooltipContainerAttributes = { + offset, + tooltipContainerInitialDimensions + } + return (
{tooltipContent({...tooltipContentArgs, - tooltipContainerOffset: offset? offset: {x:0, y:0}})} + tooltipContainerAttributes})}
) } From a95a9383440346e7374db9a639c3088c0c073703 Mon Sep 17 00:00:00 2001 From: trisianto Date: Sun, 27 Oct 2019 13:32:57 -0700 Subject: [PATCH 2/2] fixed type --- src/components/TooltipPositioner.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/TooltipPositioner.tsx b/src/components/TooltipPositioner.tsx index a722fc52..dc84ee5b 100644 --- a/src/components/TooltipPositioner.tsx +++ b/src/components/TooltipPositioner.tsx @@ -5,7 +5,12 @@ type Props = { tooltipContentArgs?: object } -class TooltipPositioner extends React.Component { +type State = { + offset: object, + tooltipContainerInitialDimensions: object +} + +class TooltipPositioner extends React.Component { private containerRef = React.createRef() state = {