-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new-rule): ARIA links, buttons, menuitems have an accessible name (
#2571) * feat(new-rule): menuitems have an accessible name * feat(new-rule): ARIA buttons, links, menuitems have a name
- Loading branch information
1 parent
c627d54
commit 9476a1f
Showing
16 changed files
with
224 additions
and
108 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": "aria-command-name", | ||
"selector": "[role=\"link\"], [role=\"button\"], [role=\"menuitem\"]", | ||
"matches": "no-naming-method-matches", | ||
"tags": ["wcag2a", "wcag412"], | ||
"metadata": { | ||
"description": "Ensures every ARIA button, link and menuitem has an accessible name", | ||
"help": "ARIA commands must have an accessible name" | ||
}, | ||
"all": [], | ||
"any": [ | ||
"aria-label", | ||
"aria-labelledby", | ||
"non-empty-title", | ||
"has-visible-text" | ||
], | ||
"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
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
53 changes: 53 additions & 0 deletions
53
test/integration/rules/aria-command-name/aria-command-name.html
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,53 @@ | ||
<!-- PASS --> | ||
<div id="pass1" role="link">Home</div> | ||
<div id="pass2" role="link" title="About"></div> | ||
<div id="pass3" role="link" aria-label="Products"></div> | ||
<div id="pass4" role="link" aria-labelledby="contact"></div> | ||
<div id="contact">Contact us</div> | ||
|
||
<div id="pass5" role="button">Submit</div> | ||
<div id="pass6" role="button" title="Upload"></div> | ||
<div id="pass7" role="button" aria-label="Download"></div> | ||
<div id="pass8" role="button" aria-labelledby="print"></div> | ||
|
||
<div role="menu"> | ||
<div id="pass9" role="menuitem">New</div> | ||
<div id="pass10" role="menuitem" title="Open"></div> | ||
<div id="pass11" role="menuitem" aria-label="Save"></div> | ||
<div id="pass12" role="menuitem" aria-labelledby="print"></div> | ||
</div> | ||
|
||
<div id="print">print file</div> | ||
|
||
<!-- FAIL --> | ||
<div id="fail1" role="link"></div> | ||
<div id="fail2" role="link" aria-labelledby="non-existant"></div> | ||
<div id="fail3" role="link" aria-labelledby="div-empty"></div> | ||
|
||
<div id="fail4" role="button"></div> | ||
<div id="fail5" role="button" aria-labelledby="non-existant"></div> | ||
<div id="fail6" role="button" aria-labelledby="div-empty"></div> | ||
|
||
<div role="menu"> | ||
<div id="fail7" role="menuitem"></div> | ||
<div id="fail8" role="menuitem" aria-labelledby="non-existant"></div> | ||
<div id="fail9" role="menuitem" aria-labelledby="div-empty"></div> | ||
</div> | ||
|
||
<div id="div-empty"></div> | ||
|
||
<!-- INAPPLICABLE --> | ||
<a href="/" role="link">Home</a> | ||
<button role="button">Save</button> | ||
<img role="button" alt="Send" id="inapplicable1" /> | ||
<div role="menu"> | ||
<input role="menuitem" title="Label" id="inapplicable2" /> | ||
<button role="menuitem" title="Label" id="inapplicable3"></button> | ||
<a href="#" role="menuitem" title="Label" id="inapplicable4"></a> | ||
<select role="menuitem" title="Label" id="inapplicable5"> | ||
<option value="volvo">Volvo</option> | ||
<option value="saab">Saab</option> | ||
<option value="opel">Opel</option> | ||
</select> | ||
<textarea role="menuitem" id="inapplicable6" title="Label"></textarea> | ||
</div> |
29 changes: 29 additions & 0 deletions
29
test/integration/rules/aria-command-name/aria-command-name.json
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,29 @@ | ||
{ | ||
"description": "aria-command-name test", | ||
"rule": "aria-command-name", | ||
"passes": [ | ||
["#pass1"], | ||
["#pass2"], | ||
["#pass3"], | ||
["#pass4"], | ||
["#pass5"], | ||
["#pass6"], | ||
["#pass7"], | ||
["#pass8"], | ||
["#pass9"], | ||
["#pass10"], | ||
["#pass11"], | ||
["#pass12"] | ||
], | ||
"violations": [ | ||
["#fail1"], | ||
["#fail2"], | ||
["#fail3"], | ||
["#fail4"], | ||
["#fail5"], | ||
["#fail6"], | ||
["#fail7"], | ||
["#fail8"], | ||
["#fail9"] | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,16 @@ | ||
<a href="#" id="violation1"></a> | ||
<a href="#" id="pass1">This link has text</a> | ||
<a href="#" id="pass3" aria-label="link text"></a> | ||
<a href="#" id="pass4" aria-labelledby="linklabel"></a> | ||
<a href="#" id="violation2" aria-labelledby="nonexistent"></a> | ||
<a href="#" id="violation3" aria-labelledby="badlabel"></a> | ||
<a href="#" id="pass2" aria-label="link text"></a> | ||
<a href="#" id="pass3" aria-labelledby="linklabel"></a> | ||
<a href="#" id="pass4" title="title text"></a> | ||
|
||
<div id="linklabel">Text</div> | ||
<div id="badlabel"></div> | ||
<span role="link" href="#" tabindex="0" id="violation4"></span> | ||
<span | ||
role="link" | ||
href="#" | ||
tabindex="0" | ||
id="pass6" | ||
aria-labelledby="linklabel" | ||
></span> | ||
<span | ||
role="link" | ||
href="#" | ||
tabindex="0" | ||
id="pass7" | ||
aria-label="Link text" | ||
></span> | ||
<span | ||
role="link" | ||
href="#" | ||
tabindex="0" | ||
id="violation5" | ||
aria-labelledby="badlabel" | ||
></span> | ||
<span | ||
role="link" | ||
href="#" | ||
tabindex="0" | ||
id="violation6" | ||
aria-labelledby="nonexistent" | ||
></span> | ||
|
||
<a href="#" id="pass8" title="title text"></a> | ||
<span role="link" href="#" tabindex="0" id="pass9" title="title text"></span> | ||
<a href="#" id="violation1"></a> | ||
<a href="#" id="violation2" aria-labelledby="nonexistent"></a> | ||
<a href="#" id="violation3" aria-labelledby="empty-label"></a> | ||
<a href="#" id="violation4" role="none"></a> | ||
<a href="#" id="violation5" role="presentation"></a> | ||
|
||
<a href="#" role="button">Does not apply</a> | ||
<div id="empty-label"></div> | ||
|
||
<a href="#" id="violation7" role="none"></a> | ||
<a href="#" id="violation8" role="presentation"></a> | ||
<span id="inapplicable1" role="link">Does not apply</span> |
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
13 changes: 0 additions & 13 deletions
13
test/integration/rules/role-button-name/role-button-name.html
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
test/integration/rules/role-button-name/role-button-name.json
This file was deleted.
Oops, something went wrong.
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,89 @@ | ||
describe('aria-command-name', function() { | ||
it('should pass for aria-label', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'link', | ||
'aria-label': 'foobar' | ||
} | ||
}); | ||
node.parent = null; | ||
|
||
var results = axe.runVirtualRule('aria-command-name', node); | ||
|
||
assert.lengthOf(results.passes, 1); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should incomplete for aria-labelledby', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'button', | ||
'aria-labelledby': 'foobar' | ||
} | ||
}); | ||
node.parent = null; | ||
|
||
var results = axe.runVirtualRule('aria-command-name', node); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 1); | ||
}); | ||
|
||
it('should pass for title', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'menuitem', | ||
title: 'foobar' | ||
} | ||
}); | ||
// children are required since titleText comes after subtree text | ||
// in accessible name calculation | ||
node.children = []; | ||
node.parent = null; | ||
|
||
var results = axe.runVirtualRule('aria-command-name', node); | ||
|
||
assert.lengthOf(results.passes, 1); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should fail when aria-label contains only whitespace', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'link', | ||
'aria-label': ' \t \n ' | ||
} | ||
}); | ||
node.children = []; | ||
|
||
var results = axe.runVirtualRule('aria-command-name', node); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 1); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should fail when title is empty', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'button', | ||
title: '' | ||
} | ||
}); | ||
node.children = []; | ||
|
||
var results = axe.runVirtualRule('aria-command-name', node); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 1); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
}); |
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
Oops, something went wrong.