-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# img-has-name | ||
|
||
img element or img role MUST has name. | ||
|
||
> All non-text content that is presented to the user has a text alternative that serves the equivalent purpose | ||
[WCAG 2.1 - 1.1.1: Non-text Content](https://www.w3.org/TR/WCAG21/#non-text-content) | ||
|
||
## :white_check_mark: Correct | ||
|
||
```html | ||
<img src="https://placebear.com/350/250" alt="bear" /> | ||
|
||
<svg role="img" aria-label="bear"></svg> | ||
``` | ||
|
||
## :warning: Incorrect | ||
|
||
```html | ||
<img src="https://placebear.com/350/250" /> | ||
``` | ||
|
||
```html | ||
<div | ||
role="img" | ||
style="background: url(https://placebear.com/350/250); width: 350px; height: 250px;" | ||
></div> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createRule } from '@acot/core'; | ||
|
||
type Options = {}; | ||
|
||
export default createRule<Options>({ | ||
type: 'contextual', | ||
selector: 'aria/[role="img"]', | ||
meta: { | ||
tags: ['wcag21a', '1.1.1 Non-text Content'], | ||
description: 'img element or img role MUST has name.', | ||
recommended: true, | ||
}, | ||
|
||
test: async (context, node) => { | ||
try { | ||
const name = await node.evaluate(async (el) => { | ||
const ax = await (window as any).getComputedAccessibleNode(el); | ||
return (ax?.name ?? '').trim(); | ||
}); | ||
|
||
context.debug('name: %s', name); | ||
|
||
if (!name) { | ||
await context.report({ | ||
node, | ||
message: 'img element or img role MUST has name.', | ||
}); | ||
} | ||
} catch (e) { | ||
context.debug('error: ', e); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters