Skip to content

Commit

Permalink
chore: modernize aria-required-children check file
Browse files Browse the repository at this point in the history
  • Loading branch information
AdnoC committed Dec 18, 2019
1 parent 06b94c2 commit 00b4059
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions lib/checks/aria/required-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function owns(node, virtualTree, role, ariaOwned) {
if (node === null) {
return false;
}
var implicit = implicitNodes(role),
selector = ['[role="' + role + '"]'];
const implicit = implicitNodes(role);
let selector = ['[role="' + role + '"]'];

if (implicit) {
selector = selector.concat(
Expand All @@ -27,28 +27,23 @@ function owns(node, virtualTree, role, ariaOwned) {
}

function ariaOwns(nodes, role) {
var index, length;

for (index = 0, length = nodes.length; index < length; index++) {
if (nodes[index] === null) {
for (const node of nodes) {
if (node === null) {
continue;
}
const virtualTree = axe.utils.getNodeFromTree(nodes[index]);
if (owns(nodes[index], virtualTree, role, true)) {
const virtualTree = axe.utils.getNodeFromTree(node);
if (owns(node, virtualTree, role, true)) {
return true;
}
}
return false;
}

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

for (index = 0; index < length; index++) {
var childRole = childRoles[index];
for (const childRole of childRoles) {
if (
owns(node, virtualNode, childRole) ||
ariaOwns(ownedElements, childRole)
Expand All @@ -66,8 +61,8 @@ function missingRequiredChildren(node, childRoles, all, role) {
// combobox exceptions
if (role === 'combobox') {
// remove 'textbox' from missing roles if combobox is a native text-type input or owns a 'searchbox'
var textboxIndex = missing.indexOf('textbox');
var textTypeInputs = ['text', 'search', 'email', 'url', 'tel'];
const textboxIndex = missing.indexOf('textbox');
const textTypeInputs = ['text', 'search', 'email', 'url', 'tel'];
if (
(textboxIndex >= 0 &&
(node.nodeName.toUpperCase() === 'INPUT' &&
Expand Down Expand Up @@ -119,21 +114,21 @@ function hasDecendantWithRole(node) {
);
}

var role = node.getAttribute('role');
var required = requiredOwned(role);
const role = node.getAttribute('role');
const required = requiredOwned(role);

if (!required) {
return true;
}

var all = false;
var childRoles = required.one;
let all = false;
let childRoles = required.one;
if (!childRoles) {
var all = true;
all = true;
childRoles = required.all;
}

var missing = missingRequiredChildren(node, childRoles, all, role);
const missing = missingRequiredChildren(node, childRoles, all, role);

if (!missing) {
return true;
Expand Down

0 comments on commit 00b4059

Please sign in to comment.