Skip to content

Commit

Permalink
fix(utils): Fix error in IE when getting scroll state on page with SV…
Browse files Browse the repository at this point in the history
…G elements. Closes #525 (#1820)
  • Loading branch information
benbcai authored and straker committed Sep 24, 2019
1 parent 330e2ec commit 9a32f6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/core/utils/scroll-state.js
Expand Up @@ -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));
},
[]
);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/core/utils/scroll-state.js
Expand Up @@ -125,6 +125,17 @@ describe('axe.utils.getScrollState', function() {
})
);
});

it('does not fail with svg elements', function() {
fixture.innerHTML =
'<svg class="svg" xmlns="http://www.w3.org/2000/svg" width="13" height="17" viewBox="0 0 13 17">' +
'<path fill="currentColor" d="M6.5 0L0 6.5 1.4 8l4-4v12.7h2V4l4.3 4L13 6.4z"></path>' +
'</svg>';

assert.doesNotThrow(function() {
getScrollState();
});
});
});

describe('axe.utils.setScrollState', function() {
Expand Down

0 comments on commit 9a32f6f

Please sign in to comment.