diff --git a/packages/vx-bounds/src/enhancers/withBoundingRects.js b/packages/vx-bounds/src/enhancers/withBoundingRects.js index 1ac88c60b..433523020 100644 --- a/packages/vx-bounds/src/enhancers/withBoundingRects.js +++ b/packages/vx-bounds/src/enhancers/withBoundingRects.js @@ -40,7 +40,7 @@ export default function withBoundingRects(BaseComponent) { componentDidMount() { this.node = ReactDOM.findDOMNode(this); - this.setState(this.getRects()); + this.setState(() => this.getRects()); } getRects() { diff --git a/packages/vx-tooltip/src/tooltips/TooltipWithBounds.js b/packages/vx-tooltip/src/tooltips/TooltipWithBounds.js index b0760268d..42a70b8aa 100644 --- a/packages/vx-tooltip/src/tooltips/TooltipWithBounds.js +++ b/packages/vx-tooltip/src/tooltips/TooltipWithBounds.js @@ -8,6 +8,8 @@ import Tooltip from './Tooltip'; const propTypes = { ...withBoundingRectsProps, ...Tooltip.propTypes, + offsetLeft: PropTypes.number, + offsetTop: PropTypes.number, }; const defaultProps = {}; @@ -15,6 +17,8 @@ const defaultProps = {}; function TooltipWithBounds({ left: initialLeft, top: initialTop, + offsetLeft = 10, + offsetTop = 10, rect, parentRect, children, @@ -24,8 +28,11 @@ function TooltipWithBounds({ let top = initialTop; if (rect && parentRect) { - left = rect.right > parentRect.right ? (left - rect.width) : left; - top = rect.bottom > parentRect.bottom ? (top - rect.height) : top; + left = (offsetLeft + rect.right) > parentRect.right + ? (left - rect.width - offsetLeft) : left + offsetLeft; + + top = (offsetTop + rect.bottom) > parentRect.bottom + ? (top - rect.height - offsetTop) : top + offsetTop; } return (