Skip to content

Commit 41a1bd5

Browse files
authored
Update img-has-alt docs for latest recommendation
Generally speaking, developers should choose to avoid ARIA attributes if the same thing can be achieved without them. In the case of images and alt text, we should prefer alt="" over role="presentation". This was discussed in #100 and fixed in #102, but the documentation wasn't fully updated to reflect this behavior. Fixes #162.
1 parent 866cb92 commit 41a1bd5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

docs/rules/img-has-alt.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This rule takes one optional object argument of type object:
1818

1919
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):
2020

21-
```js
21+
```jsx
2222
// Image.js
2323
const Image = props => {
2424
const {
@@ -42,7 +42,7 @@ return (
4242
);
4343
```
4444

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:
4646

4747
#### Bad
4848
```jsx
@@ -85,4 +85,5 @@ function Foo(props) {
8585
<img {...props} alt /> // Has no value
8686
<img {...props} alt={undefined} /> // Has no value
8787
<img {...props} alt={`${undefined}`} /> // Has no value
88+
<img src="foo" role="presentation" /> // Avoid ARIA if it can be achieved without
8889
```

0 commit comments

Comments
 (0)