Skip to content

Commit

Permalink
fix(aria-required-children): allow combobox to own a searchbox (#1708)
Browse files Browse the repository at this point in the history
* fix(aria-required-children): allow combobox to own a searchbox

* add subclass and superclass roles

* determine subclassRole from superclassRole

* fix tests

* get role inheritance

* fix map

* fix comment

* revert superclass role changes

* fix test

* fix broken code
  • Loading branch information
straker committed Aug 20, 2019
1 parent b4e2ecf commit 42158ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/checks/aria/required-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function owns(node, virtualTree, role, ariaOwned) {
selector = ['[role="' + role + '"]'];

if (implicit) {
selector = selector.concat(implicit);
selector = selector.concat(
implicit.map(implicitSelector => implicitSelector + ':not([role])')
);
}

selector = selector.join(',');
Expand Down Expand Up @@ -62,13 +64,15 @@ function missingRequiredChildren(node, childRoles, all, role) {

// combobox exceptions
if (role === 'combobox') {
// remove 'textbox' from missing roles if combobox is a native text-type input
// 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'];
if (
textboxIndex >= 0 &&
node.nodeName.toUpperCase() === 'INPUT' &&
textTypeInputs.includes(node.type)
(textboxIndex >= 0 &&
(node.nodeName.toUpperCase() === 'INPUT' &&
textTypeInputs.includes(node.type))) ||
(owns(node, virtualNode, 'searchbox') ||
ariaOwns(ownedElements, 'searchbox'))
) {
missing.splice(textboxIndex, 1);
}
Expand Down
18 changes: 18 additions & 0 deletions test/checks/aria/required-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,24 @@ describe('aria-required-children', function() {
);
});

it('should pass role comboxbox when child is native "search" input type', function() {
var params = checkSetup(
'<div role="combobox" id="target"><input type="search"><p role="listbox">Textbox</p></div>'
);
assert.isTrue(
checks['aria-required-children'].evaluate.apply(checkContext, params)
);
});

it('should not accept implicit nodes with a different role', function() {
var params = checkSetup(
'<div role="combobox" id="target"><input type="search" role="spinbutton"><p role="listbox">Textbox</p></div>'
);
assert.isFalse(
checks['aria-required-children'].evaluate.apply(checkContext, params)
);
});

describe('options', function() {
it('should return undefined instead of false when the role is in options.reviewEmpty', function() {
var params = checkSetup('<div role="grid" id="target"></div>');
Expand Down

0 comments on commit 42158ac

Please sign in to comment.