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

fix(aria-required-parent): allow nested group and presentational roles #3492

Merged
merged 3 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 12 additions & 13 deletions lib/checks/aria/aria-required-parent-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,30 @@ function getMissingContext(
return null;
}

const allowsGroup = reqContext.includes('group');
let vNode = includeElement ? virtualNode : virtualNode.parent;

while (vNode) {
const parentRole = getRole(vNode);
const role = getRole(vNode, { noPresentational: true });

// if parent node has role=group and role=group is an allowed
// context, check next parent
if (reqContext.includes('group') && parentRole === 'group') {
// if parent node has no role or is presentational, or if role
// allows group, we keep parsing the parent tree.
// this means intermediate roles between a required parent and
// child will fail the check
if (!role) {
vNode = vNode.parent;
} else if (role === 'group' && allowsGroup) {
// Allow the own role; i.e. tree > treeitem > group > treeitem
if (ownGroupRoles.includes(explicitRole)) {
reqContext.push(explicitRole);
}
reqContext = reqContext.filter(r => r !== 'group');
vNode = vNode.parent;
continue;
}

// if parent node has a role that is not the required role and not
// presentational we will fail the check
if (reqContext.includes(parentRole)) {
} else if (reqContext.includes(role)) {
return null;
} else if (parentRole && !['presentation', 'none'].includes(parentRole)) {
} else {
return reqContext;
}

vNode = vNode.parent;
}

return reqContext;
Expand Down
11 changes: 11 additions & 0 deletions test/checks/aria/required-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ describe('aria-required-parent', function() {
);
});

it('should pass for multiple group and presentational roles', function() {
var params = checkSetup(
'<div role="list"><div role="none"><div role="group"><div role="none"><div role="group"><div role="listitem" id="target">Nothing here.</div></div></div></div></div></div>'
);
assert.isTrue(
axe.testUtils
.getCheckEvaluate('aria-required-parent')
.apply(checkContext, params)
);
});

(shadowSupported ? it : xit)(
'should pass when required parent is present across shadow boundary',
function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,15 @@
<div role="option" id="pass13">option</div>
</div>
</div>

<div role="tree">
<ul role="group">
<li role="none">
<ul role="group">
<li role="none">
<div role="treeitem" id="pass14">tree item</div>
</li>
</ul>
</li>
</ul>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
["#pass10"],
["#pass11"],
["#pass12"],
["#pass13"]
["#pass13"],
["#pass14"]
]
}