Skip to content

Commit

Permalink
fix(aftershow): call afterShow only after state has fully updated
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartSpitzner committed Feb 9, 2022
1 parent 8d260dc commit 54752e8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,11 @@ class ReactTooltip extends React.Component {
show: true
},
() => {
this.updatePosition();
if (isInvisible && afterShow) {
afterShow(e);
}
this.updatePosition(() => {
if (isInvisible && afterShow) {
afterShow(e);
}
});
}
);
}
Expand Down Expand Up @@ -692,7 +693,7 @@ class ReactTooltip extends React.Component {
}

// Calculation the position
updatePosition() {
updatePosition(callbackAfter) {
const {
currentEvent,
currentTarget,
Expand Down Expand Up @@ -727,10 +728,12 @@ class ReactTooltip extends React.Component {
if (result.isNewState) {
// Switch to reverse placement
return this.setState(result.newState, () => {
this.updatePosition();
this.updatePosition(callbackAfter);
});
}

callbackAfter();

// Set tooltip position
node.style.left = result.position.left + 'px';
node.style.top = result.position.top + 'px';
Expand Down

0 comments on commit 54752e8

Please sign in to comment.