Skip to content

Commit

Permalink
fix(getposition): no error when all placements outside
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartSpitzner committed Feb 15, 2022
1 parent 982d89d commit 249b925
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class ReactTooltip extends React.Component {
e,
e.currentTarget,
this.tooltipRef,
desiredPlace,
desiredPlace.split(',')[0],
desiredPlace,
effect,
offset
Expand All @@ -443,7 +443,9 @@ class ReactTooltip extends React.Component {
);
}

const place = result.isNewState ? result.newState.place : desiredPlace;
const place = result.isNewState
? result.newState.place
: desiredPlace.split(',')[0];

// To prevent previously created timers from triggering
this.clearTimer();
Expand Down
7 changes: 4 additions & 3 deletions src/utils/getPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ export default function(e, target, node, place, desiredPlace, effect, offset) {
right: inside('right')
};

function firstInside() {
function choose() {
const allPlaces = desiredPlace
.split(',')
.concat(place, ['top', 'bottom', 'left', 'right']);
for (const d of allPlaces) {
if (placeIsInside[d]) return d;
}
return null;
// if nothing is inside, just use the old place.
return place;
}

const chosen = firstInside();
const chosen = choose();

let isNewState = false;
let newPlace;
Expand Down

0 comments on commit 249b925

Please sign in to comment.