Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 24 additions & 9 deletions lib/checks/aria/valid-attr-value.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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>
Original file line number Diff line number Diff line change
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"]]
}