Skip to content

Commit

Permalink
fix: add auto error
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Jun 27, 2020
1 parent 38914aa commit d7f9525
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 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
28 changes: 24 additions & 4 deletions src/utils/computeAutoPlacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,34 @@ 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) => {
Expand Down

0 comments on commit d7f9525

Please sign in to comment.