source: frontend/node_modules/eslint-plugin-jsx-a11y/docs/rules/img-redundant-alt.md

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

Fix frontend appearance

  • Property mode set to 100644
File size: 1.8 KB
Line 
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
7Enforce 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
11This 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
24For 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
26For 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
28The 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
45General best practice (reference resources)
46
47### Resources
48- [WebAIM, Alternative Text](https://webaim.org/techniques/alttext/)
Note: See TracBrowser for help on using the repository browser.