From a1c63a2fb54b9d728535656c3c68164984d1ea1e Mon Sep 17 00:00:00 2001 From: Wang Shenwei Date: Tue, 15 Jul 2025 16:20:10 +0800 Subject: [PATCH] fix(collectScroller): handle element in shadow DOM closes #555 --- src/util.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util.ts b/src/util.ts index 5170d86b..d2072d44 100644 --- a/src/util.ts +++ b/src/util.ts @@ -76,18 +76,23 @@ export function getWin(ele: HTMLElement) { */ export function collectScroller(ele: HTMLElement) { const scrollerList: HTMLElement[] = []; - let current = ele?.parentElement; + let current = ele?.parentNode; const scrollStyle = ['hidden', 'scroll', 'clip', 'auto']; while (current) { - const { overflowX, overflowY, overflow } = - getWin(current).getComputedStyle(current); - if ([overflowX, overflowY, overflow].some((o) => scrollStyle.includes(o))) { - scrollerList.push(current); + if (current instanceof HTMLElement) { + const { overflowX, overflowY, overflow } = + getWin(current).getComputedStyle(current); + if ([overflowX, overflowY, overflow].some((o) => scrollStyle.includes(o))) { + scrollerList.push(current); + } + } else if (current instanceof ShadowRoot) { + current = current.host; + continue; } - current = current.parentElement; + current = current.parentNode; } return scrollerList;