You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/img-has-alt.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ This rule takes one optional object argument of type object:
18
18
19
19
For the `components` option, these strings determine which JSX elements (**always including**`<img>`) should be checked for having `alt` prop. This is a good use case when you have a wrapper component that simply renders an `img` element (like in React):
20
20
21
-
```js
21
+
```jsx
22
22
// Image.js
23
23
constImage=props=> {
24
24
const {
@@ -42,7 +42,7 @@ return (
42
42
);
43
43
```
44
44
45
-
Note that passing props as spread attribute without `alt` explicitly defined will cause this rule to fail. Explicitly pass down `alt` prop or use `role="presentation"`for rule to pass. Use `Image` component above as a reference for destructuring and applying the prop. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.** For example:
45
+
Note that passing props as spread attribute without `alt` explicitly defined will cause this rule to fail. Explicitly pass down `alt` prop for rule to pass. Use `Image` component above as a reference for destructuring and applying the prop. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.** For example:
46
46
47
47
#### Bad
48
48
```jsx
@@ -85,4 +85,5 @@ function Foo(props) {
85
85
<img {...props} alt />// Has no value
86
86
<img {...props} alt={undefined} />// Has no value
87
87
<img {...props} alt={`${undefined}`} />// Has no value
88
+
<img src="foo" role="presentation"/>// Avoid ARIA if it can be achieved without
0 commit comments