From 2d50e75ea8cb7350d025e55dd7e0585ecc44be8d Mon Sep 17 00:00:00 2001 From: mengxiong10 <15623530290@163.com> Date: Mon, 2 Mar 2020 13:55:23 +0800 Subject: [PATCH] fix: popup doesn't reposition when scrolling in Firefox (#427) --- src/util/dom.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/util/dom.js b/src/util/dom.js index 090a8e0..195aeff 100644 --- a/src/util/dom.js +++ b/src/util/dom.js @@ -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); }