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(rule): add additional elements to check for incomplete with required children #1547

Merged
merged 3 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions lib/checks/aria/required-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@ function ariaOwns(nodes, role) {
}

function missingRequiredChildren(node, childRoles, all, role) {
var i,
l = childRoles.length,
var index,
length = childRoles.length,
missing = [],
ownedElements = idrefs(node, 'aria-owns');

for (i = 0; i < l; i++) {
var r = childRoles[i];
if (owns(node, virtualNode, r) || ariaOwns(ownedElements, r)) {
for (index = 0; index < length; index++) {
var childRole = childRoles[index];
if (
owns(node, virtualNode, childRole) ||
ariaOwns(ownedElements, childRole)
) {
if (!all) {
return null;
}
} else {
if (all) {
missing.push(r);
missing.push(childRole);
}
}
}
Expand Down Expand Up @@ -109,7 +112,12 @@ if (!missing) {

this.data(missing);

if (reviewEmpty.includes(role)) {
// Only review empty nodes when a node is both empty and does not have an aria-owns relationship
if (
reviewEmpty.includes(role) &&
node.children.length === 0 &&
idrefs(node, 'aria-owns').length === 0
scurker marked this conversation as resolved.
Show resolved Hide resolved
) {
return undefined;
} else {
return false;
Expand Down
13 changes: 12 additions & 1 deletion lib/checks/aria/required-children.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@
"id": "aria-required-children",
"evaluate": "required-children.js",
"options": {
"reviewEmpty": ["listbox"]
"reviewEmpty": [
"doc-bibliography",
"doc-endnotes",
"grid",
"list",
"listbox",
"table",
"tablist",
"tree",
"treegrid",
"rowgroup"
]
},
"metadata": {
"impact": "critical",
Expand Down
12 changes: 9 additions & 3 deletions lib/commons/aria/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,9 @@ lookupTable.role = {
attributes: {
allowed: ['aria-expanded', 'aria-errormessage']
},
owned: null,
owned: {
one: ['doc-biblioentry']
},
nameFrom: ['author'],
context: null,
unsupported: false,
Expand Down Expand Up @@ -746,7 +748,9 @@ lookupTable.role = {
attributes: {
allowed: ['aria-expanded', 'aria-errormessage']
},
owned: ['doc-endnote'],
owned: {
one: ['doc-endnote']
},
namefrom: ['author'],
context: null,
unsupported: false,
Expand Down Expand Up @@ -1280,7 +1284,9 @@ lookupTable.role = {
'aria-errormessage'
]
},
owned: null,
owned: {
one: ['menuitem', 'menuitemradio', 'menuitemcheckbox']
},
nameFrom: ['author'],
context: null,
unsupported: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<div role="list" id="pass1"><div role="listitem" id="pass2">Item 1</div></div>
<div role="list" id="pass3" aria-owns="pass4"></div>
<div role="listitem" id="pass4"></div>
<div role="list" id="fail1"></div>
<div role="list" id="fail2"><div role="menuitem" id="pass5"></div></div>
<div role="list" id="fail3" aria-owns="pass6"></div>
<div role="list" id="fail1"><div role="menuitem" id="pass5"></div></div>
<div role="list" id="fail2" aria-owns="pass6"></div>
<div role="menu" id="fail3"></div>
<div role="menubar" id="fail4"></div>
<div role="row" id="fail5"></div>
<div role="menuitem" id="pass6"></div>
<div role="list" id="pass7" aria-owns="parent"></div>
<div id="parent"><div role="listitem" id="pass8"></div></div>
<div role="listbox" id="incomplete1"></div>
<div role="grid" id="incomplete1"></div>
<div role="list" id="incomplete2"></div>
<div role="listbox" id="incomplete3"></div>
<div role="table" id="incomplete4"></div>
<div role="tablist" id="incomplete5"></div>
<div role="tree" id="incomplete6"></div>
<div role="treegrid" id="incomplete7"></div>
<div role="rowgroup" id="incomplete8"></div>
<div role="doc-bibliography" id="incomplete9"></div>
<div role="doc-endnotes" id="incomplete10"></div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"description": "aria-required-children test",
"rule": "aria-required-children",
"violations": [["#fail1"], ["#fail2"], ["#fail3"]],
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"], ["#fail5"]],
"passes": [
["#pass1"],
["#pass2"],
Expand All @@ -12,5 +12,16 @@
["#pass7"],
["#pass8"]
],
"incomplete": [["#incomplete1"]]
"incomplete": [
["#incomplete1"],
["#incomplete2"],
["#incomplete3"],
["#incomplete4"],
["#incomplete5"],
["#incomplete6"],
["#incomplete7"],
["#incomplete8"],
["#incomplete9"],
["#incomplete10"]
]
}