Skip to content

Commit

Permalink
fix(aria-valid-attr-value): mark as needs review for aria-current wit…
Browse files Browse the repository at this point in the history
…h invalid value (#1998)

* fix(aria-valid-attr-value): mark as needs review for aria-current with invalid value

* revert page-has-main
  • Loading branch information
straker committed Jan 27, 2020
1 parent 7447d03 commit 39b8eae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
33 changes: 24 additions & 9 deletions lib/checks/aria/valid-attr-value.js
@@ -1,6 +1,7 @@
options = Array.isArray(options) ? options : [];

const needsReview = [];
let needsReview = '';
let messageKey = '';
const invalid = [];
const aria = /^aria-/;
const attrs = axe.utils.getNodeAttributes(node);
Expand All @@ -11,26 +12,37 @@ const preChecks = {
// aria-controls should only check if element exists if the element
// doesn't have aria-expanded=false or aria-selected=false (tabs)
// @see https://github.com/dequelabs/axe-core/issues/1463
'aria-controls': function() {
'aria-controls': () => {
return (
node.getAttribute('aria-expanded') !== 'false' &&
node.getAttribute('aria-selected') !== 'false'
);
},
// aria-current should mark as needs review if any value is used that is
// not one of the valid values (since any value is treated as "true")
'aria-current': () => {
if (!axe.commons.aria.validateAttrValue(node, 'aria-current')) {
needsReview = `aria-current="${node.getAttribute('aria-current')}"`;
messageKey = 'ariaCurrent';
}

return;
},
// aria-owns should only check if element exists if the element
// doesn't have aria-expanded=false (combobox)
// @see https://github.com/dequelabs/axe-core/issues/1524
'aria-owns': function() {
'aria-owns': () => {
return node.getAttribute('aria-expanded') !== 'false';
},
// aria-describedby should not mark missing element as violation but
// instead as needs review
// @see https://github.com/dequelabs/axe-core/issues/1151
'aria-describedby': function() {
'aria-describedby': () => {
if (!axe.commons.aria.validateAttrValue(node, 'aria-describedby')) {
needsReview.push(
`aria-describedby="${node.getAttribute('aria-describedby')}"`
);
needsReview = `aria-describedby="${node.getAttribute(
'aria-describedby'
)}"`;
messageKey = 'noId';
}

return;
Expand All @@ -52,8 +64,11 @@ for (let i = 0, l = attrs.length; i < l; i++) {
}
}

if (needsReview.length) {
this.data(needsReview);
if (needsReview) {
this.data({
messageKey,
needsReview
});
return undefined;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/checks/aria/valid-attr-value.json
Expand Up @@ -11,8 +11,8 @@
"plural": "Invalid ARIA attribute values: ${data.values}"
},
"incomplete": {
"singular": "ARIA attribute element ID does not exist on the page: ${data.values}",
"plural": "ARIA attributes element ID does not exist on the page: ${data.values}"
"noId": "ARIA attribute element ID does not exist on the page: ${data.needsReview}",
"ariaCurrent": "ARIA attribute value is invalid and will be treated as \"aria-current=true\": ${data.needsReview}"
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/checks/aria/valid-attr-value.js
Expand Up @@ -213,6 +213,14 @@ describe('aria-valid-attr-value', function() {
);
});

it('should return undefined on aria-current with invalid value', function() {
fixtureSetup('<button aria-current="test">Button</button>');
var undefined1 = fixture.querySelector('button');
assert.isUndefined(
checks['aria-valid-attr-value'].evaluate.call(checkContext, undefined1)
);
});

describe('options', function() {
it('should exclude supplied attributes', function() {
fixture.innerHTML =
Expand Down
Expand Up @@ -11,7 +11,6 @@ <h2>Violations</h2>

<div aria-checked="stuff" id="violation6">hi</div>
<div aria-controls="stuff" id="violation7">hi</div>
<div aria-current="stage" id="violation8">hi</div>
<div aria-disabled="stuff" id="violation10">hi</div>
<div aria-dropeffect="stuff" id="violation11">hi</div>
<div aria-expanded="stuff" id="violation12">hi</div>
Expand Down Expand Up @@ -270,4 +269,5 @@ <h2>Possible False Positives</h2>
<div id="ref2">Hi2</div>

<div aria-describedby="stuff" id="incomplete1">hi</div>
<div aria-current="stage" id="incomplete2">hi</div>
</div>
Expand Up @@ -9,7 +9,6 @@
["#violation5"],
["#violation6"],
["#violation7"],
["#violation8"],
["#violation10"],
["#violation11"],
["#violation12"],
Expand Down Expand Up @@ -224,5 +223,5 @@
["#pass183"],
["#pass184"]
],
"incomplete": [["#incomplete1"]]
"incomplete": [["#incomplete1"], ["#incomplete2"]]
}

0 comments on commit 39b8eae

Please sign in to comment.