Skip to content

Commit

Permalink
Allow title attribute OR aria-label attribute in the anchor-has-conte…
Browse files Browse the repository at this point in the history
…nt rule
  • Loading branch information
gorohash committed May 3, 2021
1 parent ff93739 commit 5177497
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions __tests__/src/rules/anchor-has-content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ ruleTester.run('anchor-has-content', rule, {
{ code: '<a>{foo.bar}</a>' },
{ code: '<a dangerouslySetInnerHTML={{ __html: "foo" }} />' },
{ code: '<a children={children} />' },
{ code: '<a title={title} />' },
{ code: '<a aria-label={ariaLabel} />' },
{ code: '<a title={title} aria-label={ariaLabel} />' },
].map(parserOptionsMapper),
invalid: [
{ code: '<a />', errors: [expectedError] },
{ code: '<a><Bar aria-hidden /></a>', errors: [expectedError] },
{ code: '<a>{undefined}</a>', errors: [expectedError] },
{ code: '<a title={title} />', errors: [expectedError] },
{ code: '<a aria-label={ariaLabel} />', errors: [expectedError] },
].map(parserOptionsMapper),
});
2 changes: 1 addition & 1 deletion docs/rules/anchor-has-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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.

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

## Rule details

Expand Down
4 changes: 2 additions & 2 deletions src/rules/anchor-has-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Rule Definition
// ----------------------------------------------------------------------------

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

Expand Down Expand Up @@ -37,7 +37,7 @@ module.exports = {
if (hasAccessibleChild(node.parent)) {
return;
}
if (hasEveryProp(node.attributes, ['title', 'aria-label'])) {
if (hasAnyProp(node.attributes, ['title', 'aria-label'])) {
return;
}

Expand Down

0 comments on commit 5177497

Please sign in to comment.