Skip to content

Commit

Permalink
Merge pull request #1143 from atomiks/fix/auto-error
Browse files Browse the repository at this point in the history
fix: add auto error
  • Loading branch information
FezVrasta committed Jun 27, 2020
2 parents baa4b33 + 1c4d05d commit 777ebbb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/modifiers/flip.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function flip({ state, options, name }: ModifierArguments<Options>) {
);
}

if (checks.every(check => check)) {
if (checks.every((check) => check)) {
firstFittingPlacement = placement;
makeFallbackChecks = false;
break;
Expand All @@ -144,10 +144,10 @@ function flip({ state, options, name }: ModifierArguments<Options>) {
const numberOfChecks = flipVariations ? 3 : 1;

for (let i = numberOfChecks; i > 0; i--) {
const fittingPlacement = placements.find(placement => {
const fittingPlacement = placements.find((placement) => {
const checks = checksMap.get(placement);
if (checks) {
return checks.slice(0, i).every(check => check);
return checks.slice(0, i).every((check) => check);
}
});

Expand Down
30 changes: 25 additions & 5 deletions src/utils/computeAutoPlacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,37 @@ export default function computeAutoPlacement(

const variation = getVariation(placement);

const placements = (variation
const placements = variation
? flipVariations
? variationPlacements
: variationPlacements.filter(
placement => getVariation(placement) === variation
(placement) => getVariation(placement) === variation
)
: basePlacements
).filter(placement => allowedAutoPlacements.indexOf(placement) >= 0);
: basePlacements;

// $FlowFixMe
let allowedPlacements = placements.filter(
(placement) => allowedAutoPlacements.indexOf(placement) >= 0
);

if (allowedPlacements.length === 0) {
allowedPlacements = placements;

if (__DEV__) {
console.error(
[
'Popper: The `allowedAutoPlacements` option did not allow any',
'placements. Ensure the `placement` option matches the variation',
'of the allowed placements.',
'For example, "auto" cannot be used to allow "bottom-start".',
'Use "auto-start" instead.',
].join(' ')
);
}
}

// $FlowFixMe: Flow seems to have problems with two array unions...
const overflows: OverflowsMap = placements.reduce((acc, placement) => {
const overflows: OverflowsMap = allowedPlacements.reduce((acc, placement) => {
acc[placement] = detectOverflow(state, {
placement,
boundary,
Expand Down

0 comments on commit 777ebbb

Please sign in to comment.