We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a947ef4 commit 3f134a6Copy full SHA for 3f134a6
packages/utils/src/dom.ts
@@ -29,5 +29,15 @@ export const syncScroll = (left: HTMLElement, right: HTMLElement) => {
29
};
30
31
32
-export const getElementRoot = (element?: HTMLElement) =>
33
- (element?.getRootNode?.() instanceof ShadowRoot ? element.getRootNode() : document) as ShadowRoot | Document;
+export const getElementRoot = (element?: HTMLElement) => {
+ 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