web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB

  1. # heading-has-content
  2. Enforce 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.
  3. ## Rule details
  4. This rule takes one optional object argument of type object:
  5. ```json
  6. {
  7. "rules": {
  8. "jsx-a11y/heading-has-content": [ 2, {
  9. "components": [ "MyHeading" ],
  10. }],
  11. }
  12. }
  13. ```
  14. For 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):
  15. ```js
  16. // Header.js
  17. const Header = props => {
  18. return (
  19. <h1 {...props}>{ props.children }</h1>
  20. );
  21. }
  22. ...
  23. // CreateAccount.js (for example)
  24. ...
  25. return (
  26. <Header>Create Account</Header>
  27. );
  28. ```
  29. #### Bad
  30. ```jsx
  31. function Foo(props) {
  32. return <label {...props} />
  33. }
  34. ```
  35. ### Succeed
  36. ```jsx
  37. <h1>Heading Content!</h1>
  38. <h1><TextWrapper /><h1>
  39. <h1 dangerouslySetInnerHTML={{ __html: 'foo' }} />
  40. ```
  41. ### Fail
  42. ```jsx
  43. <h1 />
  44. <h1><TextWrapper aria-hidden />
  45. ```
  46. ## Accessibility guidelines
  47. - [WCAG 2.4.6](https://www.w3.org/TR/UNDERSTANDING-WCAG20/navigation-mechanisms-descriptive.html)
  48. ### Resources
  49. - [axe-core, empty-heading](https://dequeuniversity.com/rules/axe/3.2/empty-heading)