diff options
Diffstat (limited to 'popperjs/package/lib/dom-utils/listScrollParents.js.flow')
-rw-r--r-- | popperjs/package/lib/dom-utils/listScrollParents.js.flow | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/popperjs/package/lib/dom-utils/listScrollParents.js.flow b/popperjs/package/lib/dom-utils/listScrollParents.js.flow new file mode 100644 index 0000000..ef86b04 --- /dev/null +++ b/popperjs/package/lib/dom-utils/listScrollParents.js.flow @@ -0,0 +1,33 @@ +// @flow +import getScrollParent from './getScrollParent'; +import getParentNode from './getParentNode'; +import getWindow from './getWindow'; +import type { Window, VisualViewport } from '../types'; +import isScrollParent from './isScrollParent'; + +/* +given a DOM element, return the list of all scroll parents, up the list of ancesors +until we get to the top window object. This list is what we attach scroll listeners +to, because if any of these parent elements scroll, we'll need to re-calculate the +reference element's position. +*/ +export default function listScrollParents( + element: Node, + list: Array<Element | Window> = [] +): Array<Element | Window | VisualViewport> { + const scrollParent = getScrollParent(element); + const isBody = scrollParent === element.ownerDocument?.body; + const win = getWindow(scrollParent); + const target = isBody + ? [win].concat( + win.visualViewport || [], + isScrollParent(scrollParent) ? scrollParent : [] + ) + : scrollParent; + const updatedList = list.concat(target); + + return isBody + ? updatedList + : // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here + updatedList.concat(listScrollParents(getParentNode(target))); +} |