Skip to content

Commit

Permalink
Merge pull request #151 from wwayne/fix
Browse files Browse the repository at this point in the history
Update postion calculation so that it can calculate continous tootlip
  • Loading branch information
wwayne authored Jul 27, 2016
2 parents 9ed3a81 + 3d69f62 commit f9bd612
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ class ReactTooltip extends Component {

// If it is focus event, switch to `solid` effect
const isFocus = e instanceof window.FocusEvent

this.setState({
placeholder,
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
Expand Down Expand Up @@ -246,8 +245,7 @@ class ReactTooltip extends Component {
const delayTime = show ? 0 : parseInt(delayShow, 10)
const eventTarget = e.currentTarget

clearTimeout(this.delayShowLoop)
this.delayShowLoop = setTimeout(() => {
const updateState = () => {
if (typeof placeholder === 'string') placeholder = placeholder.trim()
if (Array.isArray(placeholder) && placeholder.length > 0 || placeholder) {
this.setState({
Expand All @@ -258,7 +256,14 @@ class ReactTooltip extends Component {
this.updatePosition()
})
}
}, delayTime)
}

if (delayShow) {
clearTimeout(this.delayShowLoop)
this.delayShowLoop = setTimeout(updateState, delayTime)
} else {
updateState()
}
}

/**
Expand All @@ -269,14 +274,21 @@ class ReactTooltip extends Component {

if (!this.mount) return

this.clearTimer()
this.delayHideLoop = setTimeout(() => {
const resetState = (resetPlace) => {
const newPlace = resetPlace ? '' : this.state.place
this.setState({
show: false,
place: ''
place: newPlace
})
this.removeScrollListener()
}, parseInt(delayHide, 10))
}

if (delayHide) {
this.clearTimer()
this.delayHideLoop = setTimeout(resetState, parseInt(delayHide, 10))
} else {
resetState(true)
}
}

/**
Expand Down

0 comments on commit f9bd612

Please sign in to comment.