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(getContainingBlock): check html in while loop #1129

Merged
merged 2 commits into from Jun 10, 2020
Merged
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
29 changes: 15 additions & 14 deletions src/dom-utils/getOffsetParent.js
Expand Up @@ -23,21 +23,22 @@ function getTrueOffsetParent(element: Element): ?Element {
function getContainingBlock(element: Element) {
let currentNode = getParentNode(element);

while (getNodeName(currentNode) !== 'body') {
if (isHTMLElement(currentNode)) {
const css = getComputedStyle(currentNode);
while (
isHTMLElement(currentNode) &&
['html', 'body'].indexOf(getNodeName(currentNode)) < 0
) {
const css = getComputedStyle(currentNode);

// This is non-exhaustive but covers the most common CSS properties that
// create a containing block.
if (
css.transform !== 'none' ||
css.perspective !== 'none' ||
css.willChange !== 'auto'
) {
return currentNode;
} else {
currentNode = currentNode.parentNode;
}
// This is non-exhaustive but covers the most common CSS properties that
// create a containing block.
if (
css.transform !== 'none' ||
css.perspective !== 'none' ||
css.willChange !== 'auto'
) {
return currentNode;
} else {
currentNode = currentNode.parentNode;
}
}

Expand Down