diff --git a/lib/commons/text/accessible-text-virtual.js b/lib/commons/text/accessible-text-virtual.js index 527b417994..b7a4f721d9 100644 --- a/lib/commons/text/accessible-text-virtual.js +++ b/lib/commons/text/accessible-text-virtual.js @@ -25,7 +25,8 @@ function findLabel(virtualNode) { label = dom.findElmsInContext({ elm: 'label', attr: 'for', value: virtualNode.actualNode.id, context: virtualNode.actualNode })[0]; - } else { + } + if (!label) { label = dom.findUpVirtual(virtualNode, 'label'); } return axe.utils.getNodeFromTree(axe._tree[0], label); diff --git a/test/commons/text/accessible-text.js b/test/commons/text/accessible-text.js index dcb4360b38..920d41857d 100644 --- a/test/commons/text/accessible-text.js +++ b/test/commons/text/accessible-text.js @@ -778,6 +778,18 @@ describe('text.accessibleTextVirtual', function() { }); }); + it('should find implicit labels with id that does not match to a label', function () { + types.forEach(function(type) { + var t = type ? ' type="' + type + '"' : ''; + fixture.innerHTML = ''; + axe._tree = axe.utils.getFlattenedTree(fixture); + + var target = axe.utils.querySelectorAll(axe._tree, 'input')[0]; + assert.equal(axe.commons.text.accessibleTextVirtual(target), 'Hello World', type); + }); + }) + // not implemented yet, doesn't work accross ATs it.skip('should find a placeholder attribute', function() { types.forEach(function(type) {