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

Run getComputedStyle in the same context as the target element #678

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
3 changes: 2 additions & 1 deletion packages/popper/src/utils/getOuterSizes.js
Expand Up @@ -6,7 +6,8 @@
* @returns {Object} object containing width and height properties
*/
export default function getOuterSizes(element) {
const styles = getComputedStyle(element);
const window = element.ownerDocument.defaultView;
const styles = window.getComputedStyle(element);
const x = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
const y = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
const result = {
Expand Down
3 changes: 2 additions & 1 deletion packages/popper/src/utils/getStyleComputedProperty.js
Expand Up @@ -10,6 +10,7 @@ export default function getStyleComputedProperty(element, property) {
return [];
}
// NOTE: 1 DOM access here
const css = getComputedStyle(element, null);
const window = element.ownerDocument.defaultView;
const css = window.getComputedStyle(element, null);
return property ? css[property] : css;
}