| 1 | # jsx-a11y/img-redundant-alt
|
|---|
| 2 |
|
|---|
| 3 | 💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
|
|---|
| 4 |
|
|---|
| 5 | <!-- end auto-generated rule header -->
|
|---|
| 6 |
|
|---|
| 7 | Enforce img alt attribute does not contain the word image, picture, or photo. Screen readers already announce `img` elements as an image. There is no need to use words such as *image*, *photo*, and/or *picture*.
|
|---|
| 8 |
|
|---|
| 9 | ## Rule options
|
|---|
| 10 |
|
|---|
| 11 | This rule takes one optional object argument of type object:
|
|---|
| 12 |
|
|---|
| 13 | ```json
|
|---|
| 14 | {
|
|---|
| 15 | "rules": {
|
|---|
| 16 | "jsx-a11y/img-redundant-alt": [ 2, {
|
|---|
| 17 | "components": [ "Image" ],
|
|---|
| 18 | "words": [ "Bild", "Foto" ],
|
|---|
| 19 | }],
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | ```
|
|---|
| 23 |
|
|---|
| 24 | 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).
|
|---|
| 25 |
|
|---|
| 26 | 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.
|
|---|
| 27 |
|
|---|
| 28 | 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.
|
|---|
| 29 |
|
|---|
| 30 | ### Succeed
|
|---|
| 31 | ```jsx
|
|---|
| 32 | <img src="foo" alt="Foo eating a sandwich." />
|
|---|
| 33 | <img src="bar" aria-hidden alt="Picture of me taking a photo of an image" /> // Will pass because it is hidden.
|
|---|
| 34 | <img src="baz" alt={`Baz taking a ${photo}`} /> // This is valid since photo is a variable name.
|
|---|
| 35 | ```
|
|---|
| 36 |
|
|---|
| 37 | ### Fail
|
|---|
| 38 | ```jsx
|
|---|
| 39 | <img src="foo" alt="Photo of foo being weird." />
|
|---|
| 40 | <img src="bar" alt="Image of me at a bar!" />
|
|---|
| 41 | <img src="baz" alt="Picture of baz fixing a bug." />
|
|---|
| 42 | ```
|
|---|
| 43 |
|
|---|
| 44 | ## Accessibility guidelines
|
|---|
| 45 | General best practice (reference resources)
|
|---|
| 46 |
|
|---|
| 47 | ### Resources
|
|---|
| 48 | - [WebAIM, Alternative Text](https://webaim.org/techniques/alttext/)
|
|---|