Skip to content

Commit 642aef8

Browse files
authored
Merge pull request #422 from vdh/heading-has-content-aria-hidden
Fix heading-has-content to ignore headers that are aria-hidden
2 parents 20e894a + f50bbd8 commit 642aef8

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

__tests__/src/rules/heading-has-content-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ ruleTester.run('heading-has-content', rule, {
3838
{ code: '<h1>{foo.bar}</h1>' },
3939
{ code: '<h1 dangerouslySetInnerHTML={{ __html: "foo" }} />' },
4040
{ code: '<h1 children={children} />' },
41+
{ code: '<h1 aria-hidden />' },
4142
].map(parserOptionsMapper),
4243
invalid: [
4344
{ code: '<h1 />', errors: [expectedError] },

src/rules/heading-has-content.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { elementType } from 'jsx-ast-utils';
1111
import { generateObjSchema, arraySchema } from '../util/schemas';
1212
import hasAccessibleChild from '../util/hasAccessibleChild';
13+
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
1314

1415
const errorMessage =
1516
'Headings must have content and the content must be accessible by a screen reader.';
@@ -43,6 +44,8 @@ module.exports = {
4344
return;
4445
} else if (hasAccessibleChild(node.parent)) {
4546
return;
47+
} else if (isHiddenFromScreenReader(nodeType, node.attributes)) {
48+
return;
4649
}
4750

4851
context.report({

0 commit comments

Comments
 (0)