Skip to content

Commit

Permalink
fix: Regression introduced by floating-ui#596 (floating-ui#599)
Browse files Browse the repository at this point in the history
More details here: floating-ui/react-popper#122
  • Loading branch information
FezVrasta authored Apr 4, 2018
1 parent a3995a2 commit 87f1d81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
14 changes: 4 additions & 10 deletions packages/popper/src/methods/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import computeAutoPlacement from '../utils/computeAutoPlacement';
import getReferenceOffsets from '../utils/getReferenceOffsets';
import getPopperOffsets from '../utils/getPopperOffsets';
import runModifiers from '../utils/runModifiers';
import getSupportedPropertyName from '../utils/getSupportedPropertyName';

/**
* Updates the position of the popper, computing the new offsets and applying
Expand All @@ -26,14 +25,6 @@ export default function update() {
offsets: {},
};

// NOTE: DOM access here
// resets the popper's position so that the document size can be calculated excluding
// the size of the popper element itself
const popperStyles = this.popper.style;
popperStyles.top = '';
popperStyles.left = '';
popperStyles[getSupportedPropertyName('transform')] = '';

// compute reference element offsets
data.offsets.reference = getReferenceOffsets(
this.state,
Expand Down Expand Up @@ -65,7 +56,10 @@ export default function update() {
data.offsets.reference,
data.placement
);
data.offsets.popper.position = this.options.positionFixed ? 'fixed' : 'absolute';

data.offsets.popper.position = this.options.positionFixed
? 'fixed'
: 'absolute';

// run the modifiers
data = runModifiers(this.modifiers, data);
Expand Down
23 changes: 20 additions & 3 deletions packages/popper/src/modifiers/preventOverflow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getOffsetParent from '../utils/getOffsetParent';
import getBoundaries from '../utils/getBoundaries';
import getSupportedPropertyName from '../utils/getSupportedPropertyName';

/**
* @function
Expand All @@ -19,13 +20,30 @@ export default function preventOverflow(data, options) {
boundariesElement = getOffsetParent(boundariesElement);
}

// NOTE: DOM access here
// resets the popper's position so that the document size can be calculated excluding
// the size of the popper element itself
const transformProp = getSupportedPropertyName('transform');
const popperStyles = data.instance.popper.style; // assignment to help minification
const { top, left, [transformProp]: transform } = popperStyles;
popperStyles.top = '';
popperStyles.left = '';
popperStyles[transformProp] = '';

const boundaries = getBoundaries(
data.instance.popper,
data.instance.reference,
options.padding,
boundariesElement,
data.positionFixed
);

// NOTE: DOM access here
// restores the original style properties after the offsets have been computed
popperStyles.top = top;
popperStyles.left = left;
popperStyles[transformProp] = transform;

options.boundaries = boundaries;

const order = options.priority;
Expand Down Expand Up @@ -60,9 +78,8 @@ export default function preventOverflow(data, options) {
};

order.forEach(placement => {
const side = ['left', 'top'].indexOf(placement) !== -1
? 'primary'
: 'secondary';
const side =
['left', 'top'].indexOf(placement) !== -1 ? 'primary' : 'secondary';
popper = { ...popper, ...check[side](placement) };
});

Expand Down

0 comments on commit 87f1d81

Please sign in to comment.