Skip to content

Commit

Permalink
fix(aria-required-attr): pass aria-checked for elements with checked …
Browse files Browse the repository at this point in the history
…property (#2226)

* fix(aria-required-attr): pass aria-checked for elements with checked property

* trigger build
  • Loading branch information
straker authored May 12, 2020
1 parent fad7982 commit 64318a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/checks/aria/aria-required-attr-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand All @@ -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']
}
});
}
};

Expand Down
15 changes: 15 additions & 0 deletions test/checks/aria/required-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ describe('aria-required-attr', function() {
);
});

it('should pass aria-checkbox if element has checked property', function() {
var vNode = queryFixture(
'<input id="target" type="checkbox" role="switch">'
);

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 = {
Expand Down

0 comments on commit 64318a5

Please sign in to comment.