Skip to content

Commit 9b21d76

Browse files
fix: support of shadow DOM (#829)
fix #822
1 parent d570097 commit 9b21d76

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ function alignNearest(
229229
return 0
230230
}
231231

232+
function getParentElement(element: Node): Element | null {
233+
const parent = element.parentElement;
234+
if (parent == null) {
235+
return (element.getRootNode() as ShadowRoot).host || null;
236+
}
237+
return parent;
238+
}
239+
232240
export default (target: Element, options: Options): CustomScrollAction[] => {
233241
//TODO: remove this hack when microbundle will support typescript >= 4.0
234242
const windowWithViewport = window as unknown as Window & {
@@ -255,7 +263,7 @@ export default (target: Element, options: Options): CustomScrollAction[] => {
255263
let cursor: Element | null = target
256264
while (isElement(cursor) && checkBoundary(cursor)) {
257265
// Move cursor to parent
258-
cursor = cursor.parentElement
266+
cursor = getParentElement(cursor)
259267

260268
// Stop when we reach the viewport
261269
if (cursor === scrollingElement) {

0 commit comments

Comments
 (0)