Skip to content

Commit 54fa569

Browse files
authored
fix(accessible-name): Allow fallback labels when input has id (#951)
1 parent 9aca329 commit 54fa569

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/commons/text/accessible-text-virtual.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ function findLabel(virtualNode) {
2525
label = dom.findElmsInContext({
2626
elm: 'label', attr: 'for', value: virtualNode.actualNode.id, context: virtualNode.actualNode
2727
})[0];
28-
} else {
28+
}
29+
if (!label) {
2930
label = dom.findUpVirtual(virtualNode, 'label');
3031
}
3132
return axe.utils.getNodeFromTree(axe._tree[0], label);

test/commons/text/accessible-text.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,18 @@ describe('text.accessibleTextVirtual', function() {
778778
});
779779
});
780780

781+
it('should find implicit labels with id that does not match to a label', function () {
782+
types.forEach(function(type) {
783+
var t = type ? ' type="' + type + '"' : '';
784+
fixture.innerHTML = '<label for="t1">Hello World' +
785+
'<input' + t + ' id="foo"></label>';
786+
axe._tree = axe.utils.getFlattenedTree(fixture);
787+
788+
var target = axe.utils.querySelectorAll(axe._tree, 'input')[0];
789+
assert.equal(axe.commons.text.accessibleTextVirtual(target), 'Hello World', type);
790+
});
791+
})
792+
781793
// not implemented yet, doesn't work accross ATs
782794
it.skip('should find a placeholder attribute', function() {
783795
types.forEach(function(type) {

0 commit comments

Comments
 (0)