Skip to content

Commit

Permalink
fix(aria-required-children): allow comboboxes with more popup roles
Browse files Browse the repository at this point in the history
  • Loading branch information
AdnoC committed Dec 18, 2019
1 parent a2ddba3 commit bcf6150
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
22 changes: 17 additions & 5 deletions lib/checks/aria/required-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,23 @@ function missingRequiredChildren(node, childRoles, all, role) {
missing.splice(textboxIndex, 1);
}

// remove 'listbox' from missing roles if combobox is collapsed
var listboxIndex = missing.indexOf('listbox');
var expanded = node.getAttribute('aria-expanded');
if (listboxIndex >= 0 && (!expanded || expanded === 'false')) {
missing.splice(listboxIndex, 1);
const expandedChildRoles = ['listbox', 'tree', 'grid', 'dialog'];
const expandedValue = node.getAttribute('aria-expanded');
const expanded = expandedValue && expandedValue !== 'false';
const popupRole = node.getAttribute('aria-haspopup') || 'listbox';

for (let index = 0; index < expandedChildRoles.length; index++) {
const expandedChildRole = expandedChildRoles[index];
// keep the specified popup type required if expanded
if (expanded && expandedChildRole === popupRole) {
continue;
}

// remove 'listbox' and company from missing roles if combobox is collapsed
const missingIndex = missing.indexOf(expandedChildRole);
if (missingIndex >= 0) {
missing.splice(missingIndex, 1);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commons/aria/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ lookupTable.role = {
required: ['aria-expanded']
},
owned: {
all: ['listbox', 'textbox']
all: ['listbox', 'tree', 'grid', 'dialog', 'textbox']
},
nameFrom: ['author'],
context: null,
Expand Down
20 changes: 20 additions & 0 deletions test/checks/aria/required-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,26 @@ describe('aria-required-children', function() {
);
});

it('should pass an expanded combobox when the required popup role matches', function() {
var params = checkSetup(
'<div role="combobox" aria-haspopup="grid" aria-expanded="true" id="target"><p role="textbox">Textbox</p><div role="grid"></div></div>'
);
assert.isTrue(
checks['aria-required-children'].evaluate.apply(checkContext, params)
);
});

it('should fail an expanded combobox when the required role is missing on children', function() {
var params = checkSetup(
'<div role="combobox" aria-haspopup="grid" aria-expanded="true" id="target"><p role="textbox">Textbox</p><div role="listbox"></div></div>'
);
assert.isFalse(
checks['aria-required-children'].evaluate.apply(checkContext, params)
);

assert.deepEqual(checkContext._data, ['grid']);
});

it('should pass one indirectly aria-owned child when one required', function() {
var params = checkSetup(
'<div role="grid" id="target" aria-owns="r"></div><div id="r"><div role="row">Nothing here.</div></div>'
Expand Down

0 comments on commit bcf6150

Please sign in to comment.