@@ -37,8 +37,8 @@ interface CustomScrollAction {
37
37
}
38
38
39
39
// @TODO better shadowdom test, 11 = document fragment
40
- function isElement ( el : any ) {
41
- return el != null && typeof el === 'object' && el . nodeType === 1
40
+ function isElement ( el : any ) : el is Element {
41
+ return typeof el === 'object' && el != null && el . nodeType === 1
42
42
}
43
43
44
44
function canOverflow (
@@ -257,10 +257,10 @@ export default (target: Element, options: Options): CustomScrollAction[] => {
257
257
258
258
// Collect all the scrolling boxes, as defined in the spec: https://drafts.csswg.org/cssom-view/#scrolling-box
259
259
const frames : Element [ ] = [ ]
260
- let cursor = target
260
+ let cursor : Element | null = target
261
261
while ( isElement ( cursor ) && checkBoundary ( cursor ) ) {
262
262
// Move cursor to parent
263
- cursor = cursor . parentNode as Element
263
+ cursor = cursor . parentElement
264
264
265
265
// Stop when we reach the viewport
266
266
if ( cursor === scrollingElement ) {
@@ -270,15 +270,16 @@ export default (target: Element, options: Options): CustomScrollAction[] => {
270
270
271
271
// Skip document.body if it's not the scrollingElement and documentElement isn't independently scrollable
272
272
if (
273
+ cursor != null &&
273
274
cursor === document . body &&
274
275
isScrollable ( cursor ) &&
275
- ! isScrollable ( document . documentElement as HTMLElement )
276
+ ! isScrollable ( document . documentElement )
276
277
) {
277
278
continue
278
279
}
279
280
280
281
// Now we check if the element is scrollable, this code only runs if the loop haven't already hit the viewport or a custom boundary
281
- if ( isScrollable ( cursor , skipOverflowHiddenElements ) ) {
282
+ if ( cursor != null && isScrollable ( cursor , skipOverflowHiddenElements ) ) {
282
283
frames . push ( cursor )
283
284
}
284
285
}
0 commit comments