Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add auto error #1143

Merged
merged 1 commit into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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