discourse/js/float-kit/addon/lib/get-scroll-parent.js
2025-10-20 14:44:46 +01:00

13 lines
455 B
JavaScript
Vendored

export function getScrollParent(node) {
const isElement = node instanceof HTMLElement;
const overflowY = isElement && window.getComputedStyle(node).overflowY;
const isScrollable = overflowY !== "visible" && overflowY !== "hidden";
if (!node || node === document.documentElement) {
return null;
} else if (isScrollable && node.scrollHeight >= node.clientHeight) {
return node;
}
return getScrollParent(node.parentNode) || window;
}