UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

31 lines (23 loc) 857 B
var findStyle = function findStyle(node, prop) { if (node instanceof HTMLElement) { return getComputedStyle(node).getPropertyValue(prop); } return ""; }; var isScrollable = function isScrollable(node) { return /(auto|scroll)/.test(findStyle(node, "overflow") + findStyle(node, "overflow-y") + findStyle(node, "overflow-x")); }; // getScrollableParent recursively checking for CSS styles which would indicate that element is scrollable. // Element can be scrollable when it's parent has overflow auto or scroll set. var getScrollableParent = function getScrollableParent(node) { if (!node || node === document.body) { return document.body; } if (isScrollable(node)) { return node; } if (node && node.parentNode) { return getScrollableParent(node.parentNode); } return null; }; export default getScrollableParent;