-
Notifications
You must be signed in to change notification settings - Fork 791
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(new-rule): ARIA links, buttons, menuitems have an accessible name #2571
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": "aria-menuitem-name", | ||
"selector": "[role=\"menuitem\"]", | ||
"matches": "aria-form-field-name-matches", | ||
"tags": ["wcag2a", "wcag412"], | ||
"metadata": { | ||
"description": "Ensures every ARIA menuitem node has an accessible name", | ||
"help": "ARIA menuitem nodes 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
32 changes: 32 additions & 0 deletions
32
test/integration/rules/aria-menuitem-name/aria-menuitem-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,32 @@ | ||
<!-- PASS --> | ||
<div role="menu"> | ||
<div id="pass1" role="menuitem">New</div> | ||
<div id="pass2" role="menuitem" title="Open"></div> | ||
<div id="pass3" role="menuitem" aria-label="Save"></div> | ||
<div id="pass4" role="menuitem" aria-labelledby="print"></div> | ||
</div> | ||
|
||
<div id="print">print file</div> | ||
|
||
<!-- FAIL --> | ||
<div role="menu"> | ||
<div id="fail1" role="menuitem"></div> | ||
<div id="fail2" role="menuitem" aria-labelledby="print-non-existant"></div> | ||
<div id="fail3" role="menuitem" aria-labelledby="print-empty"></div> | ||
</div> | ||
|
||
<div id="print-empty"></div> | ||
|
||
<!-- INAPPLICABLE --> | ||
<div role="menu"> | ||
<img role="menuitem" alt="Label" id="inapplicable1" /> | ||
<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> |
6 changes: 6 additions & 0 deletions
6
test/integration/rules/aria-menuitem-name/aria-menuitem-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,6 @@ | ||
{ | ||
"description": "aria-menuitem-name test", | ||
"rule": "aria-menuitem-name", | ||
"passes": [["#pass1"], ["#pass2"], ["#pass3"], ["#pass4"]], | ||
"violations": [["#fail1"], ["#fail2"], ["#fail3"]] | ||
} |
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-menuitem-name', function() { | ||
it('should pass for aria-label', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'menuitem', | ||
'aria-label': 'foobar' | ||
} | ||
}); | ||
node.parent = null; | ||
|
||
var results = axe.runVirtualRule('aria-menuitem-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: 'menuitem', | ||
'aria-labelledby': 'foobar' | ||
} | ||
}); | ||
node.parent = null; | ||
|
||
var results = axe.runVirtualRule('aria-menuitem-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-menuitem-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: 'menuitem', | ||
'aria-label': ' \t \n ' | ||
} | ||
}); | ||
node.children = []; | ||
|
||
var results = axe.runVirtualRule('aria-menuitem-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: 'menuitem', | ||
title: '' | ||
} | ||
}); | ||
node.children = []; | ||
|
||
var results = axe.runVirtualRule('aria-menuitem-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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to think of a way to make sure we don't forget to do this. Any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could generate the file like we do the other test html files. I've not looked into that part of the build but it should be possible.