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.

44 lines
1.7 KiB

  1. # img-redundant-alt
  2. Enforce img alt attribute does not contain the word image, picture, or photo. Screenreaders already announce `img` elements as an image. There is no need to use words such as *image*, *photo*, and/or *picture*.
  3. ## Rule details
  4. This rule takes one optional object argument of type object:
  5. ```json
  6. {
  7. "rules": {
  8. "jsx-a11y/img-redundant-alt": [ 2, {
  9. "components": [ "Image" ],
  10. "words": [ "Bild", "Foto" ],
  11. }],
  12. }
  13. }
  14. ```
  15. For the `components` option, these strings determine which JSX elements (**always including** `<img>`) should be checked for having redundant words in the `alt` prop value . This is a good use case when you have a wrapper component that simply renders an `img` element (like in React).
  16. For the `words` option, these strings can be used to specify custom words that should be checked for in the alt prop, including `image`, `photo`, and `picture`. Useful for specifying words in other languages.
  17. The rule will first check if `aria-hidden` is true to determine whether to enforce the rule. If the image is hidden, then rule will always succeed.
  18. ### Succeed
  19. ```jsx
  20. <img src="foo" alt="Foo eating a sandwich." />
  21. <img src="bar" aria-hidden alt="Picture of me taking a photo of an image" /> // Will pass because it is hidden.
  22. <img src="baz" alt={`Baz taking a ${photo}`} /> // This is valid since photo is a variable name.
  23. ```
  24. ### Fail
  25. ```jsx
  26. <img src="foo" alt="Photo of foo being weird." />
  27. <img src="bar" alt="Image of me at a bar!" />
  28. <img src="baz" alt="Picture of baz fixing a bug." />
  29. ```
  30. ## Accessibility guidelines
  31. General best practice (reference resources)
  32. ### Resources
  33. - [WebAIM, Alternative Text](https://webaim.org/techniques/alttext/)