-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(image-alt): require alt text or empty strings (#1260)
* feat(image-alt): require alt text or empty strings The image-alt rule now checks for space characters, and fails if they are present. Empty alt attributes are still fine, and text content is still fine. This fixes cases where ATs do not skip decorative images because of the space characters in the alt attribute. Closes #1174 * chore: include updated build files (there are no actual changes) * chore: rename to alt-space-value, focus on images * fix: PR feedback
- Loading branch information
1 parent
9930bb9
commit e24cea9
Showing
7 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const validAttrValue = /^\s+$/.test(node.getAttribute('alt')); | ||
return node.hasAttribute('alt') && validAttrValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, which is not ignored by all screen readers" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,5 @@ | |
"role-presentation", | ||
"role-none" | ||
], | ||
"none": [] | ||
"none": ["alt-space-value"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
{ | ||
"id": "landmark-complementary-is-top-level", | ||
"selector": "aside:not([role]), [role=complementary]", | ||
"tags": [ | ||
"cat.semantics", | ||
"best-practice" | ||
], | ||
"metadata": { | ||
"description": "Ensures the complementary landmark or aside is at top level", | ||
"help": "Aside must not be contained in another landmark" | ||
}, | ||
"all": [], | ||
"any": [ | ||
"landmark-is-top-level" | ||
], | ||
"none": [] | ||
"id": "landmark-complementary-is-top-level", | ||
"selector": "aside:not([role]), [role=complementary]", | ||
"tags": ["cat.semantics", "best-practice"], | ||
"metadata": { | ||
"description": "Ensures the complementary landmark or aside is at top level", | ||
"help": "Aside must not be contained in another landmark" | ||
}, | ||
"all": [], | ||
"any": ["landmark-is-top-level"], | ||
"none": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=" " />'); | ||
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)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters