From 2ad92f67205fd370c3ad5ba44274248c2b9fe6e5 Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Thu, 16 Dec 2021 12:00:08 +0100 Subject: [PATCH] fix(custom-elms): Don't error on custom Element.children prop (#3326) * fix(custom-elms): Don't error on custom Element.children prop * for index loop --- lib/commons/aria/get-accessible-refs.js | 6 ++++-- test/commons/aria/get-accessible-refs.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/commons/aria/get-accessible-refs.js b/lib/commons/aria/get-accessible-refs.js index 0ff919dcbc..534f60ca1b 100644 --- a/lib/commons/aria/get-accessible-refs.js +++ b/lib/commons/aria/get-accessible-refs.js @@ -33,8 +33,10 @@ function cacheIdRefs(node, idRefs, refAttrs) { } } - for (let i = 0; i < node.children.length; i++) { - cacheIdRefs(node.children[i], idRefs, refAttrs); + for (let i = 0; i < node.childNodes.length; i++) { + if (node.childNodes[i].nodeType === 1) { + cacheIdRefs(node.childNodes[i], idRefs, refAttrs); + } } } diff --git a/test/commons/aria/get-accessible-refs.js b/test/commons/aria/get-accessible-refs.js index af625117f5..541d8fc4a5 100644 --- a/test/commons/aria/get-accessible-refs.js +++ b/test/commons/aria/get-accessible-refs.js @@ -68,6 +68,18 @@ describe('aria.getAccessibleRefs', function() { assert.deepEqual(getAccessibleRefs(node), [ref1, ref2]); }); + it('does not break on a custom .children property', function() { + setLookup({ 'aria-foo': { type: 'idref' } }); + fixture.innerHTML = '
'; + var node = document.getElementById('foo'); + var ref = document.getElementById('ref'); + + Object.defineProperty(node, 'children', { + value: ['#ref'] + }); + assert.deepEqual(getAccessibleRefs(node), [ref]); + }); + (shadowSupport ? it : xit)('works inside shadow DOM', function() { setLookup({ 'aria-bar': { type: 'idref' } }); fixture.innerHTML = '
';