From 4a0da8b4f6ad27810f10370bf1d3b129b0e5050b Mon Sep 17 00:00:00 2001 From: an4ger Date: Mon, 20 Aug 2018 15:53:20 +0300 Subject: [PATCH] fix(index.js): Use correct orientation when mouse enters getPosition has to be called before first setting the state (and thus rendering the tooltip) when mouse enters, to take into account cases when the position is close to the client window edge #388 --- src/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 597e4d43..6877ddda 100644 --- a/src/index.js +++ b/src/index.js @@ -280,14 +280,21 @@ class ReactTooltip extends React.Component { // To prevent previously created timers from triggering this.clearTimer() + // Make sure the correct place is set + let node = ReactDOM.findDOMNode(this) + let desiredPlace = e.currentTarget.getAttribute('data-place') || this.props.place || 'top' + let effect = switchToSolid && 'solid' || this.getEffect(e.currentTarget) + let offset = e.currentTarget.getAttribute('data-offset') || this.props.offset || {} + let result = getPosition(e, e.currentTarget, ReactDOM.findDOMNode(this), desiredPlace, desiredPlace, effect, offset) + this.setState({ originTooltip: originTooltip, isMultiline: isMultiline, - desiredPlace: e.currentTarget.getAttribute('data-place') || this.props.place || 'top', - place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top', + desiredPlace: desiredPlace, + place: result.isNewState ? result.newState.place : desiredPlace, type: e.currentTarget.getAttribute('data-type') || this.props.type || 'dark', - effect: switchToSolid && 'solid' || this.getEffect(e.currentTarget), - offset: e.currentTarget.getAttribute('data-offset') || this.props.offset || {}, + effect: effect, + offset: offset, html: e.currentTarget.getAttribute('data-html') ? e.currentTarget.getAttribute('data-html') === 'true' : (this.props.html || false), @@ -485,4 +492,4 @@ class ReactTooltip extends React.Component { } /* export default not fit for standalone, it will exports {default:...} */ -module.exports = ReactTooltip +module.exports = ReactTooltip \ No newline at end of file