Skip to content

Commit

Permalink
fix(index.js): Use correct orientation when mouse enters
Browse files Browse the repository at this point in the history
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

ReactTooltip#388
  • Loading branch information
an4ger committed Aug 20, 2018
1 parent 86f3cf8 commit 4a0da8b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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

0 comments on commit 4a0da8b

Please sign in to comment.