Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion __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} />' },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i didn't look closely at this before, but having both title and aria-label is definitely going to create inconsistency across screen readers, so this one should be moved to invalid as well.

thank you so much for taking this on! glad to see some movements.

)).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: '<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')) {
return;
}

Expand Down
Loading