Skip to content

Commit 3f134a6

Browse files
update
1 parent a947ef4 commit 3f134a6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/utils/src/dom.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,15 @@ export const syncScroll = (left: HTMLElement, right: HTMLElement) => {
2929
};
3030
};
3131

32-
export const getElementRoot = (element?: HTMLElement) =>
33-
(element?.getRootNode?.() instanceof ShadowRoot ? element.getRootNode() : document) as ShadowRoot | Document;
32+
export const getElementRoot = (element?: HTMLElement) => {
33+
if (element) {
34+
const root = element.getRootNode();
35+
36+
if (root instanceof ShadowRoot) {
37+
return root;
38+
}
39+
40+
return element.ownerDocument;
41+
}
42+
return document;
43+
};

0 commit comments

Comments
 (0)