refactor: use overflow-y to determine scroll container

By using `overflow-y` instead of `overflow` using `endsWith` can be
avoided and represents the data we are actually interested in here
more accurately.
This commit is contained in:
Johann150 2022-07-06 19:02:39 +02:00
parent ac6b8f3480
commit 7775eb9641
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -2,12 +2,8 @@ type ScrollBehavior = 'auto' | 'smooth' | 'instant';
export function getScrollContainer(el: HTMLElement | null): HTMLElement | null {
if (el == null || el.tagName === 'HTML') return null;
const overflow = window.getComputedStyle(el).getPropertyValue('overflow');
if (
// xとyを個別に指定している場合、`hidden scroll`みたいな値になる
overflow.endsWith('scroll') ||
overflow.endsWith('auto')
) {
const overflow = window.getComputedStyle(el).getPropertyValue('overflow-y');
if (overflow === 'scroll' || overflow === 'auto') {
return el;
} else {
return getScrollContainer(el.parentElement);