Skip to content

Commit

Permalink
fix(listitem): do not fail for parent with role=presentation|none
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Jun 16, 2020
1 parent 2176794 commit a3ddc6e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/checks/lists/listitem.js
Expand Up @@ -7,7 +7,7 @@ if (!parent) {
const parentTagName = parent.nodeName.toUpperCase();
const parentRole = (parent.getAttribute('role') || '').toLowerCase();

if (parentRole === 'list') {
if (['presentation', 'none', 'list'].includes(parentRole)) {
return true;
}

Expand Down
14 changes: 14 additions & 0 deletions test/checks/lists/listitem.js
Expand Up @@ -29,6 +29,20 @@ describe('listitem', function() {
assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
});

it('should pass if the listitem has a parent role=none', function() {
fixture.innerHTML =
'<ul role="none"><li id="target">My list item</li></ul>';
var target = fixture.querySelector('#target');
assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
});

it('should pass if the listitem has a parent role=presentation', function() {
fixture.innerHTML =
'<ul role="presentation"><li id="target">My list item</li></ul>';
var target = fixture.querySelector('#target');
assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
});

it('should fail if the listitem has an incorrect parent', function() {
fixture.innerHTML = '<div><li id="target">My list item</li></div>';
var target = fixture.querySelector('#target');
Expand Down
6 changes: 6 additions & 0 deletions test/integration/rules/listitem/listitem.html
Expand Up @@ -7,6 +7,12 @@
<ol>
<li id="alsocontained">Also belongs to a list.</li>
</ol>
<ul role="presentation">
<li id="presentation">Does belong to a list.</li>
</ul>
<ul role="none">
<li id="none">Does belong to a list.</li>
</ul>
<ul role="menubar">
<li id="ulrolechanged">Also does not belong to a list.</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/rules/listitem/listitem.json
Expand Up @@ -2,5 +2,5 @@
"description": "listitem test",
"rule": "listitem",
"violations": [["#uncontained"], ["#ulrolechanged"], ["#olrolechanged"]],
"passes": [["#contained"], ["#alsocontained"]]
"passes": [["#contained"], ["#alsocontained"], ["#presentation"], ["#none"]]
}

0 comments on commit a3ddc6e

Please sign in to comment.