Skip to content

Commit

Permalink
fix(accessible-name): Allow fallback labels when input has id (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored Jun 21, 2018
1 parent 9aca329 commit 54fa569
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/commons/text/accessible-text-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions test/commons/text/accessible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<label for="t1">Hello World' +
'<input' + t + ' id="foo"></label>';
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) {
Expand Down

0 comments on commit 54fa569

Please sign in to comment.