Skip to content

Commit

Permalink
fix: popup doesn't reposition when scrolling in Firefox (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Mar 2, 2020
1 parent be26d2a commit 2d50e75
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/util/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ export function getRelativePosition(el, targetWidth, targetHeight, fixed) {
return { left: `${left}px`, top: `${top}px` };
}

export function getScrollParent(node, until = document) {
export function getScrollParent(node, until = document.body) {
if (!node || node === until) {
return null;
}

if (node.scrollHeight > node.clientHeight) {
return node;
}
return getScrollParent(node.parentNode, until);
const style = (value, prop) => getComputedStyle(value, null).getPropertyValue(prop);

const regex = /(auto|scroll)/;

const scroll = regex.test(
style(node, 'overflow') + style(node, 'overflow-y') + style(node, 'overflow-x')
);

return scroll ? node : getScrollParent(node.parentNode, until);
}

0 comments on commit 2d50e75

Please sign in to comment.