Skip to content

Commit 557f7c2

Browse files
authored
Merge pull request #26 from vue-a11y/anchor-has-content-label
For the `anchor-has-content` rule, allow anchors with explicit aria labels to pass
2 parents 6d8f7df + ad20512 commit 557f7c2

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- For the `anchor-has-content` rule, allow anchors with explicit aria labels to pass.
12+
913
## [0.2.0] - 2020-06-26
1014

1115
### Changed

src/rules/__tests__/anchor-has-content.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ makeRuleTester("anchor-has-content", rule, {
88
"<a v-text='msg' />",
99
"<a v-html='msg' />",
1010
"<a><slot /></a>",
11-
"<Anchor />"
11+
"<Anchor />",
12+
"<a aria-label='This is my label' />"
1213
],
1314
invalid: [
1415
"<a />",

src/rules/anchor-has-content.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const {
22
defineTemplateBodyVisitor,
33
getElementType,
4+
hasAriaLabel,
45
hasContent,
56
makeDocsURL
67
} = require("../utils");
@@ -34,7 +35,11 @@ module.exports = {
3435
const elementTypes = ["a"].concat(components);
3536
const elementType = getElementType(node);
3637

37-
if (elementTypes.includes(elementType) && !hasContent(node)) {
38+
if (
39+
elementTypes.includes(elementType) &&
40+
!hasContent(node) &&
41+
!hasAriaLabel(node)
42+
) {
3843
context.report({ node, messageId: "default" });
3944
}
4045
}

0 commit comments

Comments
 (0)