Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -37,14 +37,14 @@ ruleTester.run('anchor-has-content', rule, {
code: '<Link>foo</Link>',
settings: { 'jsx-a11y': { components: { Link: 'a' } } },
},
{ code: '<a title={title} />' },
{ code: '<a aria-label={ariaLabel} />' },
{ code: '<a title={title} aria-label={ariaLabel} />' },
)).map(parserOptionsMapper),
invalid: parsers.all([].concat(
{ 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 title={title} aria-label={ariaLabel} />', errors: [expectedError] },
{
code: '<Link />',
errors: [expectedError],
Expand Down
3 changes: 1 addition & 2 deletions docs/rules/anchor-has-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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` prop or the `aria-label` prop.
Alternatively, you may use the `aria-label` prop.

## Rule options

Expand Down Expand Up @@ -47,7 +47,6 @@ return (
<a>Anchor Content!</a>
<a><TextWrapper /></a>
<a dangerouslySetInnerHTML={{ __html: 'foo' }} />
<a title='foo' />
<a aria-label='foo' />
```

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 { hasAnyProp } from 'jsx-ast-utils';
import { hasProp } from 'jsx-ast-utils';

import getElementType from '../util/getElementType';
import { arraySchema, generateObjSchema } from '../util/schemas';
Expand Down Expand Up @@ -42,7 +42,7 @@ export default {
if (hasAccessibleChild(node.parent, elementType)) {
return;
}
if (hasAnyProp(node.attributes, ['title', 'aria-label'])) {
if (hasProp(node.attributes, 'aria-label') && !hasProp(node.attributes, 'title')) {
return;
}

Expand Down
Loading