Skip to content

Commit 3d69f62

Browse files
committed
Update postion calculation so that it can calculate continous tootlip
1 parent 9ed3a81 commit 3d69f62

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

Diff for: src/index.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ class ReactTooltip extends Component {
202202

203203
// If it is focus event, switch to `solid` effect
204204
const isFocus = e instanceof window.FocusEvent
205-
206205
this.setState({
207206
placeholder,
208207
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
@@ -246,8 +245,7 @@ class ReactTooltip extends Component {
246245
const delayTime = show ? 0 : parseInt(delayShow, 10)
247246
const eventTarget = e.currentTarget
248247

249-
clearTimeout(this.delayShowLoop)
250-
this.delayShowLoop = setTimeout(() => {
248+
const updateState = () => {
251249
if (typeof placeholder === 'string') placeholder = placeholder.trim()
252250
if (Array.isArray(placeholder) && placeholder.length > 0 || placeholder) {
253251
this.setState({
@@ -258,7 +256,14 @@ class ReactTooltip extends Component {
258256
this.updatePosition()
259257
})
260258
}
261-
}, delayTime)
259+
}
260+
261+
if (delayShow) {
262+
clearTimeout(this.delayShowLoop)
263+
this.delayShowLoop = setTimeout(updateState, delayTime)
264+
} else {
265+
updateState()
266+
}
262267
}
263268

264269
/**
@@ -269,14 +274,21 @@ class ReactTooltip extends Component {
269274

270275
if (!this.mount) return
271276

272-
this.clearTimer()
273-
this.delayHideLoop = setTimeout(() => {
277+
const resetState = (resetPlace) => {
278+
const newPlace = resetPlace ? '' : this.state.place
274279
this.setState({
275280
show: false,
276-
place: ''
281+
place: newPlace
277282
})
278283
this.removeScrollListener()
279-
}, parseInt(delayHide, 10))
284+
}
285+
286+
if (delayHide) {
287+
this.clearTimer()
288+
this.delayHideLoop = setTimeout(resetState, parseInt(delayHide, 10))
289+
} else {
290+
resetState(true)
291+
}
280292
}
281293

282294
/**

0 commit comments

Comments
 (0)