Skip to content

Commit

Permalink
Merge pull request #723 from jsx-eslint/fix-634
Browse files Browse the repository at this point in the history
[fix:635] Ignore control elements that are hidden
  • Loading branch information
jessebeach authored Jul 6, 2020
2 parents 592c2cc + 2b7f6b7 commit 615cacd
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 615cacd

Please sign in to comment.