Last active
June 30, 2022 09:40
-
-
Save THEtheChad/e1d349e4d4d1e0e833c62a275b11b76a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function getScrollParent(node?: Node | null) { | |
if (!(node instanceof HTMLElement)) return null; | |
if (typeof window.getComputedStyle !== 'function') return null; | |
const overflowY = window.getComputedStyle(node).overflowY || 'visible'; | |
const isScrollable = /^(visible|hidden)/.test(overflowY); | |
if (isScrollable && node.scrollHeight >= node.clientHeight) { | |
return node; | |
} | |
return getScrollParent(node.parentNode) || document.body; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment