source: frontend/node_modules/eslint-plugin-jsx-a11y/docs/rules/anchor-has-content.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.6 KB
Line 
1# jsx-a11y/anchor-has-content
2
3💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
5<!-- end auto-generated rule header -->
6
7Enforce 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.
8
9Alternatively, you may use the `title` prop or the `aria-label` prop.
10
11## Rule options
12
13This rule takes one optional object argument of type object:
14
15```json
16{
17 "rules": {
18 "jsx-a11y/anchor-has-content": [ 2, {
19 "components": [ "Anchor" ],
20 }],
21 }
22}
23```
24
25For the `components` option, these strings determine which JSX elements (**always including** `<a>`) should be checked for having content. This is a good use case when you have a wrapper component that simply renders an `a` element (like in React):
26
27```js
28// Anchor.js
29const Anchor = props => {
30 return (
31 <a {...props}>{ props.children }</a>
32 );
33}
34
35...
36
37// CreateAccount.js (for example)
38...
39return (
40 <Anchor>Create Account</Anchor>
41);
42```
43
44
45### Succeed
46```jsx
47<a>Anchor Content!</a>
48<a><TextWrapper /></a>
49<a dangerouslySetInnerHTML={{ __html: 'foo' }} />
50<a title='foo' />
51<a aria-label='foo' />
52```
53
54### Fail
55```jsx
56<a />
57<a><TextWrapper aria-hidden /></a>
58```
59## Accessibility guidelines
60- [WCAG 2.4.4](https://www.w3.org/WAI/WCAG21/Understanding/link-purpose-in-context)
61- [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value)
62
63### Resources
64- [axe-core, link-name](https://dequeuniversity.com/rules/axe/3.2/link-name)
Note: See TracBrowser for help on using the repository browser.