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

feat(image-alt): require alt text or empty strings #1260

Merged
merged 7 commits into from Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion doc/aria-supported.md
Expand Up @@ -18,4 +18,4 @@ For a detailed description about how accessibility support is decided, see [How
| -------------------- | ---------------- |
| aria-describedat | No |
| aria-details | No |
| aria-roledescription | No |
| aria-roledescription | No |
152 changes: 76 additions & 76 deletions doc/rule-descriptions.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/checks/label/alt-space-value.js
@@ -0,0 +1,2 @@
let validAttrValue = /^\s+$/.test(node.getAttribute('alt'));
return node.hasAttribute('alt') && validAttrValue;
11 changes: 11 additions & 0 deletions lib/checks/label/alt-space-value.json
@@ -0,0 +1,11 @@
{
"id": "alt-space-value",
"evaluate": "alt-space-value.js",
"metadata": {
"impact": "critical",
"messages": {
"pass": "Element has a valid alt attribute value",
"fail": "Element has an alt attribute containing only a space character"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer that we be explicit that alt attributes with white space only is not ignored by all screen readers. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine by me, I've updated the PR.

}
}
}
2 changes: 1 addition & 1 deletion lib/rules/image-alt.json
Expand Up @@ -21,5 +21,5 @@
"role-presentation",
"role-none"
],
"none": []
"none": ["alt-space-value"]
}
31 changes: 31 additions & 0 deletions test/checks/label/alt-space.js
@@ -0,0 +1,31 @@
describe('alt-space-value', function() {
'use strict';

var checkSetup = axe.testUtils.checkSetup;
var checkContext = axe.testUtils.MockCheckContext();
var check = checks['alt-space-value'];

afterEach(function() {
checkContext.reset();
});

it('should return true if alt contains a space character', function() {
var params = checkSetup('<img id="target" alt=" " />');
assert.isTrue(check.evaluate.apply(checkContext, params));
});

it('should return true if alt contains a non-breaking space character', function() {
var params = checkSetup('<img id="target" alt="&nbsp;" />');
assert.isTrue(check.evaluate.apply(checkContext, params));
});

it('should return false if alt attribute is empty', function() {
var params = checkSetup('<img id="target" alt="" />');
assert.isFalse(check.evaluate.apply(checkContext, params));
});

it('should return false if alt attribute has a proper text value', function() {
var params = checkSetup('<img id="target" alt="text content" />');
assert.isFalse(check.evaluate.apply(checkContext, params));
});
});
1 change: 1 addition & 0 deletions test/integration/rules/image-alt/image-alt.html
Expand Up @@ -15,5 +15,6 @@
<img src="img.jpg" id="pass7" role="none">
<img src="img.jpg" id="pass8" aria-labelledby="ninjamonkeys">
<div role="img" alt="blah" id="violation6"></div>
<img src="img.jpg" id="violation7" alt=" " />
<div role="img" aria-label="blah" id="pass9"></div>
<svg role="img" id="ignore1"><title>SVG Title</title></svg>
3 changes: 2 additions & 1 deletion test/integration/rules/image-alt/image-alt.json
Expand Up @@ -7,7 +7,8 @@
["#violation3"],
["#violation4"],
["#violation5"],
["#violation6"]
["#violation6"],
["#violation7"]
],
"passes": [
["#pass1"],
Expand Down