From 42158ac55e44dc20f3699a6d795f8ae3a34c35b8 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Tue, 20 Aug 2019 08:28:34 -0600 Subject: [PATCH] fix(aria-required-children): allow combobox to own a searchbox (#1708) * 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 --- lib/checks/aria/required-children.js | 14 +++++++++----- test/checks/aria/required-children.js | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/checks/aria/required-children.js b/lib/checks/aria/required-children.js index afbf76f822..8183bc1d4f 100644 --- a/lib/checks/aria/required-children.js +++ b/lib/checks/aria/required-children.js @@ -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(','); @@ -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); } diff --git a/test/checks/aria/required-children.js b/test/checks/aria/required-children.js index cc6bfe00ad..959d561a4f 100644 --- a/test/checks/aria/required-children.js +++ b/test/checks/aria/required-children.js @@ -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( + '

Textbox

' + ); + assert.isTrue( + checks['aria-required-children'].evaluate.apply(checkContext, params) + ); + }); + + it('should not accept implicit nodes with a different role', function() { + var params = checkSetup( + '

Textbox

' + ); + 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('
');