UNPKG

@nex-ui/react

Version:

🎉 A beautiful, modern, and reliable React component library.

37 lines (33 loc) • 1.13 kB
'use strict'; var utils = require('@nex-ui/utils'); var dom = require('./dom.cjs'); const getNearestOverflowAncestor = (element)=>{ const { parentElement } = element; if (!parentElement) { return utils.ownerWindow(element); } if (dom.isHTMLElement(parentElement) && dom.isOverflowElement(parentElement)) { return parentElement; } return getNearestOverflowAncestor(parentElement); }; const getOverflowAncestors = (element)=>{ const scrollableAncestors = []; const win = utils.ownerWindow(element); let ancestor = getNearestOverflowAncestor(element); let body = null; while(ancestor){ const elementName = dom.getElementName(ancestor); if (elementName === 'body') { body = ancestor; } else if (elementName === 'html' && body) { scrollableAncestors.push(body); } else { scrollableAncestors.push(ancestor); } if (win === ancestor) break; ancestor = getNearestOverflowAncestor(ancestor); } return scrollableAncestors; }; exports.getOverflowAncestors = getOverflowAncestors;