From 9a32f6fb817651d0a263d69a50b37018edc08bd8 Mon Sep 17 00:00:00 2001 From: Ben Cai Date: Tue, 24 Sep 2019 14:09:52 -0500 Subject: [PATCH] fix(utils): Fix error in IE when getting scroll state on page with SVG elements. Closes #525 (#1820) --- lib/core/utils/scroll-state.js | 17 ++++++++++------- test/core/utils/scroll-state.js | 11 +++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/core/utils/scroll-state.js b/lib/core/utils/scroll-state.js index c1b66d04d5..3fe7261006 100644 --- a/lib/core/utils/scroll-state.js +++ b/lib/core/utils/scroll-state.js @@ -14,13 +14,16 @@ function setScroll(elm, top, left) { * Create an array scroll positions from descending elements */ function getElmScrollRecursive(root) { - return Array.from(root.children).reduce((scrolls, elm) => { - const scroll = axe.utils.getScroll(elm); - if (scroll) { - scrolls.push(scroll); - } - return scrolls.concat(getElmScrollRecursive(elm)); - }, []); + return Array.from(root.children || root.childNodes || []).reduce( + (scrolls, elm) => { + const scroll = axe.utils.getScroll(elm); + if (scroll) { + scrolls.push(scroll); + } + return scrolls.concat(getElmScrollRecursive(elm)); + }, + [] + ); } /** diff --git a/test/core/utils/scroll-state.js b/test/core/utils/scroll-state.js index 8df4d6700c..f7b1d4f18f 100644 --- a/test/core/utils/scroll-state.js +++ b/test/core/utils/scroll-state.js @@ -125,6 +125,17 @@ describe('axe.utils.getScrollState', function() { }) ); }); + + it('does not fail with svg elements', function() { + fixture.innerHTML = + '' + + '' + + ''; + + assert.doesNotThrow(function() { + getScrollState(); + }); + }); }); describe('axe.utils.setScrollState', function() {