Skip to content

Commit

Permalink
[fix:634] Ignore control elements that are hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebeach committed Jul 4, 2020
1 parent 7a34e45 commit 381b9d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions __tests__/src/rules/control-has-associated-label-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,15 @@ ruleTester.run(`${ruleName}:strict`, rule, {
.map(ruleOptionsMapperFactory(strictOptions))
.map(parserOptionsMapper),
});

ruleTester.run(`${ruleName}:no-config`, rule, {
valid: [
{ code: '<input type="hidden" />' },
{ code: '<input type="text" aria-hidden="true" />' },
]
.map(parserOptionsMapper),
invalid: [
{ code: '<input type="text" />', errors: [expectedError] },
]
.map(parserOptionsMapper),
});
6 changes: 6 additions & 0 deletions src/rules/control-has-associated-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import includes from 'array-includes';
import { generateObjSchema, arraySchema } from '../util/schemas';
import type { ESLintContext } from '../../flow/eslint';
import isDOMElement from '../util/isDOMElement';
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
import isInteractiveElement from '../util/isInteractiveElement';
import isInteractiveRole from '../util/isInteractiveRole';
import mayHaveAccessibleLabel from '../util/mayHaveAccessibleLabel';
Expand Down Expand Up @@ -67,10 +68,15 @@ module.exports = {
}
const props = node.openingElement.attributes;
const nodeIsDOMElement = isDOMElement(tag);
const nodeIsHiddenFromScreenReader = isHiddenFromScreenReader(tag, props);
const nodeIsInteractiveElement = isInteractiveElement(tag, props);
const nodeIsInteractiveRole = isInteractiveRole(tag, props);
const nodeIsControlComponent = controlComponents.indexOf(tag) > -1;

if (nodeIsHiddenFromScreenReader) {
return;
}

let hasAccessibleLabel = true;
if (
nodeIsInteractiveElement
Expand Down

0 comments on commit 381b9d6

Please sign in to comment.