From 16a06e35bce02f42e5d5234983088078c793843c Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 21 Dec 2020 09:41:38 -0700 Subject: [PATCH 1/3] fix(aria-required-children): only match for roles that require children --- doc/rule-descriptions.md | 2 +- lib/core/base/metadata-function-map.js | 2 ++ lib/rules/aria-required-children-matches.js | 8 ++++++ lib/rules/aria-required-children.json | 1 + .../aria-required-children-matches.js | 27 +++++++++++++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lib/rules/aria-required-children-matches.js create mode 100644 test/rule-matches/aria-required-children-matches.js diff --git a/doc/rule-descriptions.md b/doc/rule-descriptions.md index 46068d5126..1d844bfb36 100644 --- a/doc/rule-descriptions.md +++ b/doc/rule-descriptions.md @@ -54,6 +54,7 @@ | [listitem](https://dequeuniversity.com/rules/axe/4.1/listitem?application=RuleDescription) | Ensures <li> elements are used semantically | Serious | cat.structure, wcag2a, wcag131 | failure | | [marquee](https://dequeuniversity.com/rules/axe/4.1/marquee?application=RuleDescription) | Ensures <marquee> elements are not used | Serious | cat.parsing, wcag2a, wcag222 | failure | | [meta-refresh](https://dequeuniversity.com/rules/axe/4.1/meta-refresh?application=RuleDescription) | Ensures <meta http-equiv="refresh"> is not used | Critical | cat.time-and-media, wcag2a, wcag2aaa, wcag221, wcag224, wcag325 | failure | +| [nested-interactive](https://dequeuniversity.com/rules/axe/4.1/nested-interactive?application=RuleDescription) | Nested interactive controls are not announced by screen readers | Serious | cat.keyboard, wcag2a, wcag412 | failure, needs review | | [object-alt](https://dequeuniversity.com/rules/axe/4.1/object-alt?application=RuleDescription) | Ensures <object> elements have alternate text | Serious | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a | failure, needs review | | [role-img-alt](https://dequeuniversity.com/rules/axe/4.1/role-img-alt?application=RuleDescription) | Ensures [role='img'] elements have alternate text | Serious | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a, ACT | failure, needs review | | [scrollable-region-focusable](https://dequeuniversity.com/rules/axe/4.1/scrollable-region-focusable?application=RuleDescription) | Elements that have scrollable content should be accessible by keyboard | Moderate | cat.keyboard, wcag2a, wcag211 | failure | @@ -100,7 +101,6 @@ Rules that do not necessarily conform to WCAG success criterion but are industry | [landmark-unique](https://dequeuniversity.com/rules/axe/4.1/landmark-unique?application=RuleDescription) | Landmarks must have a unique role or role/label/title (i.e. accessible name) combination | Moderate | cat.semantics, best-practice | failure | | [meta-viewport-large](https://dequeuniversity.com/rules/axe/4.1/meta-viewport-large?application=RuleDescription) | Ensures <meta name="viewport"> can scale a significant amount | Minor | cat.sensory-and-visual-cues, best-practice | failure | | [meta-viewport](https://dequeuniversity.com/rules/axe/4.1/meta-viewport?application=RuleDescription) | Ensures <meta name="viewport"> does not disable text scaling and zooming | Critical | cat.sensory-and-visual-cues, best-practice, ACT | failure | -| [nested-interactive](https://dequeuniversity.com/rules/axe/4.1/nested-interactive?application=RuleDescription) | Ensure interactive controls are not nested | Serious | cat.keyboard, best-practice | failure, needs review | | [page-has-heading-one](https://dequeuniversity.com/rules/axe/4.1/page-has-heading-one?application=RuleDescription) | Ensure that the page, or at least one of its frames contains a level-one heading | Moderate | cat.semantics, best-practice | failure | | [presentation-role-conflict](https://dequeuniversity.com/rules/axe/4.1/presentation-role-conflict?application=RuleDescription) | Flags elements whose role is none or presentation and which cause the role conflict resolution to trigger. | Minor | cat.aria, best-practice | failure | | [region](https://dequeuniversity.com/rules/axe/4.1/region?application=RuleDescription) | Ensures all page content is contained by landmarks | Moderate | cat.keyboard, best-practice | failure | diff --git a/lib/core/base/metadata-function-map.js b/lib/core/base/metadata-function-map.js index 6e40a4a1af..54478a02b7 100644 --- a/lib/core/base/metadata-function-map.js +++ b/lib/core/base/metadata-function-map.js @@ -132,6 +132,7 @@ import ariaAllowedAttrMatches from '../../rules/aria-allowed-attr-matches'; import ariaAllowedRoleMatches from '../../rules/aria-allowed-role-matches'; import ariaHasAttrMatches from '../../rules/aria-has-attr-matches'; import ariaHiddenFocusMatches from '../../rules/aria-hidden-focus-matches'; +import ariaRequiredChildrenMatches from '../../rules/aria-required-children-matches'; import autocompleteMatches from '../../rules/autocomplete-matches'; import bypassMatches from '../../rules/bypass-matches'; import colorContrastMatches from '../../rules/color-contrast-matches'; @@ -303,6 +304,7 @@ const metadataFunctionMap = { 'aria-form-field-name-matches': noNamingMethodMatches, 'aria-has-attr-matches': ariaHasAttrMatches, 'aria-hidden-focus-matches': ariaHiddenFocusMatches, + 'aria-required-children-matches': ariaRequiredChildrenMatches, 'autocomplete-matches': autocompleteMatches, 'bypass-matches': bypassMatches, 'color-contrast-matches': colorContrastMatches, diff --git a/lib/rules/aria-required-children-matches.js b/lib/rules/aria-required-children-matches.js new file mode 100644 index 0000000000..d30f0fc4f0 --- /dev/null +++ b/lib/rules/aria-required-children-matches.js @@ -0,0 +1,8 @@ +import { requiredOwned, getRole } from '../commons/aria'; + +function ariaRequiredChildrenMatches(node, virtualNode) { + const role = getRole(virtualNode); + return !!requiredOwned(role); +} + +export default ariaRequiredChildrenMatches; diff --git a/lib/rules/aria-required-children.json b/lib/rules/aria-required-children.json index fac887685c..6d7527665b 100644 --- a/lib/rules/aria-required-children.json +++ b/lib/rules/aria-required-children.json @@ -1,6 +1,7 @@ { "id": "aria-required-children", "selector": "[role]", + "matches": "aria-required-children-matches", "tags": ["cat.aria", "wcag2a", "wcag131"], "metadata": { "description": "Ensures elements with an ARIA role that require child roles contain them", diff --git a/test/rule-matches/aria-required-children-matches.js b/test/rule-matches/aria-required-children-matches.js new file mode 100644 index 0000000000..0d2bd3f544 --- /dev/null +++ b/test/rule-matches/aria-required-children-matches.js @@ -0,0 +1,27 @@ +describe('aria-required-children-matches', function() { + 'use strict'; + + var fixture = document.getElementById('fixture'); + var queryFixture = axe.testUtils.queryFixture; + var rule; + + beforeEach(function() { + rule = axe._audit.rules.find(function(rule) { + return rule.id === 'aria-required-children'; + }); + }); + + afterEach(function() { + fixture.innerHTML = ''; + }); + + it('should return true for a role that requires children', function() { + var vNode = queryFixture('
'); + assert.isTrue(rule.matches(null, vNode)); + }); + + it('should return false for a role that does not require children', function() { + var vNode = queryFixture(''); + assert.isFalse(rule.matches(null, vNode)); + }); +}); From 720830e0edd09dce00dd9b11f9ff8fe91b00c5a5 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 21 Dec 2020 09:43:05 -0700 Subject: [PATCH 2/3] fix --- doc/rule-descriptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/rule-descriptions.md b/doc/rule-descriptions.md index 1d844bfb36..46068d5126 100644 --- a/doc/rule-descriptions.md +++ b/doc/rule-descriptions.md @@ -54,7 +54,6 @@ | [listitem](https://dequeuniversity.com/rules/axe/4.1/listitem?application=RuleDescription) | Ensures <li> elements are used semantically | Serious | cat.structure, wcag2a, wcag131 | failure | | [marquee](https://dequeuniversity.com/rules/axe/4.1/marquee?application=RuleDescription) | Ensures <marquee> elements are not used | Serious | cat.parsing, wcag2a, wcag222 | failure | | [meta-refresh](https://dequeuniversity.com/rules/axe/4.1/meta-refresh?application=RuleDescription) | Ensures <meta http-equiv="refresh"> is not used | Critical | cat.time-and-media, wcag2a, wcag2aaa, wcag221, wcag224, wcag325 | failure | -| [nested-interactive](https://dequeuniversity.com/rules/axe/4.1/nested-interactive?application=RuleDescription) | Nested interactive controls are not announced by screen readers | Serious | cat.keyboard, wcag2a, wcag412 | failure, needs review | | [object-alt](https://dequeuniversity.com/rules/axe/4.1/object-alt?application=RuleDescription) | Ensures <object> elements have alternate text | Serious | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a | failure, needs review | | [role-img-alt](https://dequeuniversity.com/rules/axe/4.1/role-img-alt?application=RuleDescription) | Ensures [role='img'] elements have alternate text | Serious | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a, ACT | failure, needs review | | [scrollable-region-focusable](https://dequeuniversity.com/rules/axe/4.1/scrollable-region-focusable?application=RuleDescription) | Elements that have scrollable content should be accessible by keyboard | Moderate | cat.keyboard, wcag2a, wcag211 | failure | @@ -101,6 +100,7 @@ Rules that do not necessarily conform to WCAG success criterion but are industry | [landmark-unique](https://dequeuniversity.com/rules/axe/4.1/landmark-unique?application=RuleDescription) | Landmarks must have a unique role or role/label/title (i.e. accessible name) combination | Moderate | cat.semantics, best-practice | failure | | [meta-viewport-large](https://dequeuniversity.com/rules/axe/4.1/meta-viewport-large?application=RuleDescription) | Ensures <meta name="viewport"> can scale a significant amount | Minor | cat.sensory-and-visual-cues, best-practice | failure | | [meta-viewport](https://dequeuniversity.com/rules/axe/4.1/meta-viewport?application=RuleDescription) | Ensures <meta name="viewport"> does not disable text scaling and zooming | Critical | cat.sensory-and-visual-cues, best-practice, ACT | failure | +| [nested-interactive](https://dequeuniversity.com/rules/axe/4.1/nested-interactive?application=RuleDescription) | Ensure interactive controls are not nested | Serious | cat.keyboard, best-practice | failure, needs review | | [page-has-heading-one](https://dequeuniversity.com/rules/axe/4.1/page-has-heading-one?application=RuleDescription) | Ensure that the page, or at least one of its frames contains a level-one heading | Moderate | cat.semantics, best-practice | failure | | [presentation-role-conflict](https://dequeuniversity.com/rules/axe/4.1/presentation-role-conflict?application=RuleDescription) | Flags elements whose role is none or presentation and which cause the role conflict resolution to trigger. | Minor | cat.aria, best-practice | failure | | [region](https://dequeuniversity.com/rules/axe/4.1/region?application=RuleDescription) | Ensures all page content is contained by landmarks | Moderate | cat.keyboard, best-practice | failure | From fbd78c6719514023a5fdffbc08e5e3e4716d8594 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 21 Dec 2020 10:31:59 -0700 Subject: [PATCH 3/3] fix tests --- lib/rules/aria-required-children-matches.js | 4 +- .../aria-required-children.html | 43 +++++++++---------- .../aria-required-children.json | 16 +------ 3 files changed, 24 insertions(+), 39 deletions(-) diff --git a/lib/rules/aria-required-children-matches.js b/lib/rules/aria-required-children-matches.js index d30f0fc4f0..0ca21cf03a 100644 --- a/lib/rules/aria-required-children-matches.js +++ b/lib/rules/aria-required-children-matches.js @@ -1,7 +1,7 @@ -import { requiredOwned, getRole } from '../commons/aria'; +import { requiredOwned, getExplicitRole } from '../commons/aria'; function ariaRequiredChildrenMatches(node, virtualNode) { - const role = getRole(virtualNode); + const role = getExplicitRole(virtualNode, { dpub: true }); return !!requiredOwned(role); } diff --git a/test/integration/rules/aria-required-children/aria-required-children.html b/test/integration/rules/aria-required-children/aria-required-children.html index fafeae32ad..aff30c2ae3 100644 --- a/test/integration/rules/aria-required-children/aria-required-children.html +++ b/test/integration/rules/aria-required-children/aria-required-children.html @@ -1,19 +1,19 @@
-
Item 1
+
Item 1
-
-
+
+
- +
-
+
- -
+ +
-
+
@@ -29,30 +29,29 @@
-
-
List item 1
+
+
List item 1
-
+
Item 1
-
-