From 1c0966726b9aa505e05f65b72101c0a61178869d Mon Sep 17 00:00:00 2001 From: Johann150 Date: Wed, 6 Jul 2022 19:02:39 +0200 Subject: [PATCH] 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. --- packages/client/src/scripts/scroll.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/client/src/scripts/scroll.ts b/packages/client/src/scripts/scroll.ts index 0643bad2f..f5bc6bf9c 100644 --- a/packages/client/src/scripts/scroll.ts +++ b/packages/client/src/scripts/scroll.ts @@ -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);