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

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

Fix frontend appearance

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