Skip to content

Commit

Permalink
Merge pull request floating-ui#1248 from popperjs/fix/1242
Browse files Browse the repository at this point in the history
fix: altAxis + tether
  • Loading branch information
FezVrasta authored Feb 20, 2021
2 parents 1b810c1 + 939b6cb commit 4d5fc59
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/modifiers/preventOverflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function preventOverflow({ state, options, name }: ModifierArguments<Options>) {
return;
}

if (checkMainAxis) {
if (checkMainAxis || checkAltAxis) {
const mainSide = mainAxis === 'y' ? top : left;
const altSide = mainAxis === 'y' ? bottom : right;
const len = mainAxis === 'y' ? 'height' : 'width';
Expand Down Expand Up @@ -148,28 +148,34 @@ function preventOverflow({ state, options, name }: ModifierArguments<Options>) {
popperOffsets[mainAxis] + minOffset - offsetModifierValue - clientOffset;
const tetherMax = popperOffsets[mainAxis] + maxOffset - offsetModifierValue;

const preventedOffset = within(
tether ? Math.min(min, tetherMin) : min,
offset,
tether ? Math.max(max, tetherMax) : max
);

popperOffsets[mainAxis] = preventedOffset;
data[mainAxis] = preventedOffset - offset;
}

if (checkAltAxis) {
const mainSide = mainAxis === 'x' ? top : left;
const altSide = mainAxis === 'x' ? bottom : right;
const offset = popperOffsets[altAxis];

const min = offset + overflow[mainSide];
const max = offset - overflow[altSide];

const preventedOffset = within(min, offset, max);

popperOffsets[altAxis] = preventedOffset;
data[altAxis] = preventedOffset - offset;
if (checkMainAxis) {
const preventedOffset = within(
tether ? Math.min(min, tetherMin) : min,
offset,
tether ? Math.max(max, tetherMax) : max
);

popperOffsets[mainAxis] = preventedOffset;
data[mainAxis] = preventedOffset - offset;
}

if (checkAltAxis) {
const mainSide = mainAxis === 'x' ? top : left;
const altSide = mainAxis === 'x' ? bottom : right;
const offset = popperOffsets[altAxis];

const min = offset + overflow[mainSide];
const max = offset - overflow[altSide];

const preventedOffset = within(
tether ? Math.min(min, tetherMin) : min,
offset,
tether ? Math.max(max, tetherMax) : max
);

popperOffsets[altAxis] = preventedOffset;
data[altAxis] = preventedOffset - offset;
}
}

state.modifiersData[name] = data;
Expand Down

0 comments on commit 4d5fc59

Please sign in to comment.