diff --git a/lib/checks/forms/labelledby.js b/lib/checks/forms/labelledby.js index a06ddd7ac4..a9b3e84263 100644 --- a/lib/checks/forms/labelledby.js +++ b/lib/checks/forms/labelledby.js @@ -3,7 +3,8 @@ this.data({ type: node.getAttribute('type') }); -var matchingNodes = document.querySelectorAll('input[type="' + +var doc = axe.commons.dom.getRootNode(node); +var matchingNodes = doc.querySelectorAll('input[type="' + axe.commons.utils.escapeSelector(node.type) + '"][name="' + axe.commons.utils.escapeSelector(node.name) + '"]'); if (matchingNodes.length <= 1) { return true; @@ -15,9 +16,9 @@ return [].map.call(matchingNodes, function (m) { return l ? l.split(/\s+/) : []; }).reduce(function (prev, curr) { return prev.filter(function (n) { - return curr.indexOf(n) !== -1; + return curr.includes(n); }); }).filter(function (n) { - var labelNode = document.getElementById(n); + var labelNode = doc.getElementById(n); return labelNode && axe.commons.text.accessibleText(labelNode); }).length !== 0; diff --git a/test/checks/forms/labelledby.js b/test/checks/forms/labelledby.js index 6525fa4b61..0c5c16f83b 100644 --- a/test/checks/forms/labelledby.js +++ b/test/checks/forms/labelledby.js @@ -3,6 +3,8 @@ describe('group-labelledby', function () { var fixture = document.getElementById('fixture'); var fixtureSetup = axe.testUtils.fixtureSetup; + var shadowSupport = axe.testUtils.shadowSupport.v1; + var checkContext = { _data: null, data: function (d) { @@ -10,6 +12,10 @@ describe('group-labelledby', function () { } }; + beforeEach(function () { + axe._tree = undefined; + }); + afterEach(function () { fixture.innerHTML = ''; checkContext._data = null; @@ -114,6 +120,38 @@ describe('group-labelledby', function () { }); }); + (shadowSupport ? it : xit) + ('should return false if label is outside of shadow boundary', function () { + fixture.innerHTML = '