Replace use of Array.from

Array.from isn't supported by any version of IE.

We still need to convert a nodelist to an array so
we can either:
1. include the polyfill for Array.from from core-js
2. use [].slice

We don't use Array.from anywhere else so this uses
the second one.
This commit is contained in:
Tom Byers
2020-10-02 14:30:10 +01:00
parent 0e32df4514
commit 2693e5e2b6

View File

@@ -29,9 +29,10 @@
this.getRangeFromElement = function (keyElement) {
const range = document.createRange();
const childNodes = Array.prototype.slice.call(keyElement.childNodes);
let prefixIndex = -1;
Array.from(keyElement.childNodes).forEach((el, idx) => {
childNodes.forEach((el, idx) => {
if ((el.nodeType === 1) && el.classList.contains('govuk-visually-hidden')) {
prefixIndex = idx;
}