-
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.
feat(acot-preset-wcag): add link-has-name
- Loading branch information
Showing
5 changed files
with
78 additions
and
6 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
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,31 @@ | ||
# link-has-name | ||
|
||
Link MUST has name. | ||
|
||
> The purpose of each link can be determined from the link text alone or from the link text together with its programmatically determined link context, except where the purpose of the link would be ambiguous to users in general. | ||
[WCAG 2.1 - 2.4.4 Link Purpose (In Context)](https://www.w3.org/TR/WCAG21/#link-purpose-in-context) | ||
|
||
> For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies. | ||
[WCAG 2.1 - 4.1.2 Name, Role, Value](https://www.w3.org/TR/WCAG21/#name-role-value) | ||
|
||
## :white_check_mark: Correct | ||
|
||
```html | ||
<a href="https://www.w3.org/TR/WCAG21/#name-role-value" | ||
>WCAG 2.1 - 4.1.2 Name, Role, Value</a | ||
> | ||
``` | ||
|
||
## :warning: Incorrect | ||
|
||
```html | ||
<a href="https://www.w3.org/TR/WCAG21/#name-role-value"></a> | ||
|
||
<style> | ||
a::after { | ||
content: 'WCAG 2.1 - 4.1.2 Name, Role, Value'; | ||
} | ||
</style> | ||
``` |
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
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
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,37 @@ | ||
import { createRule } from '@acot/core'; | ||
|
||
type Options = {}; | ||
|
||
export default createRule<Options>({ | ||
type: 'contextual', | ||
selector: 'aria/[role="link"]', | ||
immutable: true, | ||
meta: { | ||
tags: [ | ||
'wcag21a', | ||
'2.4.4 Link Purpose (In Context)', | ||
'4.1.2 Name, Role, Value', | ||
], | ||
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: 'Link MUST has name.', | ||
}); | ||
} | ||
} catch (e) { | ||
context.debug('error: ', e); | ||
} | ||
}, | ||
}); |