Skip to content

Commit 5177497

Browse files
committed
Allow title attribute OR aria-label attribute in the anchor-has-content rule
1 parent ff93739 commit 5177497

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ ruleTester.run('anchor-has-content', rule, {
3232
{ code: '<a>{foo.bar}</a>' },
3333
{ code: '<a dangerouslySetInnerHTML={{ __html: "foo" }} />' },
3434
{ code: '<a children={children} />' },
35+
{ code: '<a title={title} />' },
36+
{ code: '<a aria-label={ariaLabel} />' },
3537
{ code: '<a title={title} aria-label={ariaLabel} />' },
3638
].map(parserOptionsMapper),
3739
invalid: [
3840
{ code: '<a />', errors: [expectedError] },
3941
{ code: '<a><Bar aria-hidden /></a>', errors: [expectedError] },
4042
{ code: '<a>{undefined}</a>', errors: [expectedError] },
41-
{ code: '<a title={title} />', errors: [expectedError] },
42-
{ code: '<a aria-label={ariaLabel} />', errors: [expectedError] },
4343
].map(parserOptionsMapper),
4444
});

docs/rules/anchor-has-content.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Enforce that anchors have content and that the content is accessible to screen readers. Accessible means that it is not hidden using the `aria-hidden` prop. Refer to the references to learn about why this is important.
44

5-
Alternatively, you may use the `title` and `aria-label` props.
5+
Alternatively, you may use the `title` prop or the `aria-label` prop.
66

77
## Rule details
88

src/rules/anchor-has-content.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Rule Definition
88
// ----------------------------------------------------------------------------
99

10-
import { elementType, hasEveryProp } from 'jsx-ast-utils';
10+
import { elementType, hasAnyProp } from 'jsx-ast-utils';
1111
import { arraySchema, generateObjSchema } from '../util/schemas';
1212
import hasAccessibleChild from '../util/hasAccessibleChild';
1313

@@ -37,7 +37,7 @@ module.exports = {
3737
if (hasAccessibleChild(node.parent)) {
3838
return;
3939
}
40-
if (hasEveryProp(node.attributes, ['title', 'aria-label'])) {
40+
if (hasAnyProp(node.attributes, ['title', 'aria-label'])) {
4141
return;
4242
}
4343

0 commit comments

Comments
 (0)