Skip to content

Commit

Permalink
fix(custom-elms): Don't error on custom Element.children prop (#3326)
Browse files Browse the repository at this point in the history
* fix(custom-elms): Don't error on custom Element.children prop

* for index loop
  • Loading branch information
WilcoFiers authored Dec 16, 2021
1 parent accafdf commit 2ad92f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/commons/aria/get-accessible-refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions test/commons/aria/get-accessible-refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div id="ref" aria-foo="foo"></div><i id="foo"></i>';
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 = '<div id="foo"></div>';
Expand Down

0 comments on commit 2ad92f6

Please sign in to comment.