Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

img-redundant-alt.md 1.5 KiB

3 lat temu
1234567891011121314151617181920212223242526272829303132333435363738
  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. ```