Skip to content

Commit dbbc544

Browse files
dylanbmarcysutton
authored andcommitted
fix: help-same-as-label for shadow DOM
1 parent e64adbc commit dbbc544

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

build/templates.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = {
2-
evaluate: 'function (node, options) {\n<%=source%>\n}',
2+
evaluate: 'function (node, options, virtualNode) {\n<%=source%>\n}',
33
after: 'function (results, options) {\n<%=source%>\n}',
44
gather: 'function (context) {\n<%=source%>\n}',
5-
matches: 'function (node) {\n<%=source%>\n}',
5+
matches: 'function (node, virtualNode) {\n<%=source%>\n}',
66
source: '(function () {\n<%=source%>\n}())',
77
commons: '<%=source%>'
88
};

lib/checks/.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"results": true,
44
"node": true,
55
"options": true,
6+
"virtualNode": true,
67
"axe": true,
78
"document": true,
89
"window": true

lib/checks/label/help-same-as-label.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var labelText = axe.commons.text.label(node),
2+
var labelText = axe.commons.text.label(virtualNode),
33
check = node.getAttribute('title');
44

55
if (!labelText) {

lib/commons/text/accessible-text.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function nonEmptyText(t) {
137137
* @return {string}
138138
*/
139139
text.accessibleText = function(element, inLabelledByContext) {
140+
//todo: implement shadowDOM
140141
var accessibleNameComputation;
141142
var encounteredNodes = [];
142143

test/checks/label/help-same-as-label.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ describe('help-same-as-label', function () {
55

66
afterEach(function () {
77
fixture.innerHTML = '';
8+
axe._tree = undefined;
89
});
910

1011
it('should return true if an element has a label and a title with the same text', function () {
@@ -14,8 +15,8 @@ describe('help-same-as-label', function () {
1415
node.setAttribute('aria-label', 'Duplicate');
1516

1617
fixture.appendChild(node);
17-
18-
assert.isTrue(checks['help-same-as-label'].evaluate(node));
18+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
19+
assert.isTrue(checks['help-same-as-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)));
1920
});
2021

2122
it('should return true if an element has a label and aria-describedby with the same text', function () {
@@ -30,7 +31,8 @@ describe('help-same-as-label', function () {
3031
fixture.appendChild(node);
3132
fixture.appendChild(dby);
3233

33-
assert.isTrue(checks['help-same-as-label'].evaluate(node));
34+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
35+
assert.isTrue(checks['help-same-as-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)));
3436
});
3537

3638

@@ -41,7 +43,8 @@ describe('help-same-as-label', function () {
4143

4244
fixture.appendChild(node);
4345

44-
assert.isFalse(checks['help-same-as-label'].evaluate(node));
46+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
47+
assert.isFalse(checks['help-same-as-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)));
4548

4649
});
4750

@@ -56,7 +59,8 @@ describe('help-same-as-label', function () {
5659
fixture.appendChild(node);
5760
fixture.appendChild(dby);
5861

59-
assert.isFalse(checks['help-same-as-label'].evaluate(node));
62+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
63+
assert.isFalse(checks['help-same-as-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)));
6064
});
6165

6266
});

0 commit comments

Comments
 (0)