From 64318a5bce02f05c6e6a1acf739c354b84b88082 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Tue, 12 May 2020 09:07:41 -0600 Subject: [PATCH] fix(aria-required-attr): pass aria-checked for elements with checked property (#2226) * fix(aria-required-attr): pass aria-checked for elements with checked property * trigger build --- lib/checks/aria/aria-required-attr-evaluate.js | 18 +++++++++++++++--- test/checks/aria/required-attr.js | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/checks/aria/aria-required-attr-evaluate.js b/lib/checks/aria/aria-required-attr-evaluate.js index 2b9cbf0da9..64b625ca35 100644 --- a/lib/checks/aria/aria-required-attr-evaluate.js +++ b/lib/checks/aria/aria-required-attr-evaluate.js @@ -7,14 +7,16 @@ import { isAriaRange } from '../../commons/forms'; import { requiredAttr } from '../../commons/aria'; -import { uniqueArray } from '../../core/utils'; +import { uniqueArray, getNodeFromTree } from '../../core/utils'; +import matches from '../../commons/matches'; function ariaRequiredAttrEvaluate(node, options = {}) { + const vNode = getNodeFromTree(node); const missing = []; - // aria-valuenow should fail if element does not have a value property - // @see https://github.com/dequelabs/axe-core/issues/1501 const preChecks = { + // aria-valuenow should fail if element does not have a value property + // @see https://github.com/dequelabs/axe-core/issues/1501 'aria-valuenow': function() { return !( isNativeTextbox(node) || @@ -24,6 +26,16 @@ function ariaRequiredAttrEvaluate(node, options = {}) { isAriaCombobox(node) || (isAriaRange(node) && node.hasAttribute('aria-valuenow')) ); + }, + // aria-checked should fail if element does not have a checked property + // @see https://github.com/dequelabs/axe-core/issues/2225 + 'aria-checked': function() { + return !matches(vNode, { + nodeName: 'input', + attributes: { + type: ['checkbox', 'radio'] + } + }); } }; diff --git a/test/checks/aria/required-attr.js b/test/checks/aria/required-attr.js index a83e171b25..5e6b52d880 100644 --- a/test/checks/aria/required-attr.js +++ b/test/checks/aria/required-attr.js @@ -52,6 +52,21 @@ describe('aria-required-attr', function() { ); }); + it('should pass aria-checkbox if element has checked property', function() { + var vNode = queryFixture( + '' + ); + + assert.isTrue( + checks['aria-required-attr'].evaluate.call( + checkContext, + vNode.actualNode, + options, + vNode + ) + ); + }); + describe('options', function() { it('should require provided attribute names for a role', function() { axe.commons.aria.lookupTable.role.mccheddarton = {