From 06b94c2a0fe7907b221496728252059909edfc9b Mon Sep 17 00:00:00 2001 From: AdnoC Date: Wed, 18 Dec 2019 14:40:03 -0500 Subject: [PATCH] fix(aria-required-children): allow comboboxes with more popup roles --- lib/checks/aria/required-children.js | 21 ++++++++++++++++----- lib/commons/aria/index.js | 2 +- test/checks/aria/required-children.js | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/lib/checks/aria/required-children.js b/lib/checks/aria/required-children.js index 2151908d6e..ddb91282c5 100644 --- a/lib/checks/aria/required-children.js +++ b/lib/checks/aria/required-children.js @@ -78,11 +78,22 @@ 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 (const expandedChildRole of expandedChildRoles) { + // 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); + } } } diff --git a/lib/commons/aria/index.js b/lib/commons/aria/index.js index f0fac21db0..c95eddccf6 100644 --- a/lib/commons/aria/index.js +++ b/lib/commons/aria/index.js @@ -433,7 +433,7 @@ lookupTable.role = { required: ['aria-expanded'] }, owned: { - all: ['listbox', 'textbox'] + all: ['listbox', 'tree', 'grid', 'dialog', 'textbox'] }, nameFrom: ['author'], context: null, diff --git a/test/checks/aria/required-children.js b/test/checks/aria/required-children.js index e447590bd4..ed3d60e22a 100644 --- a/test/checks/aria/required-children.js +++ b/test/checks/aria/required-children.js @@ -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( + '

Textbox

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

Textbox

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