Skip to content

Commit 36661b4

Browse files
authored
Merge pull request #8 from vue-a11y/updates
Fix hasContent check for slots and handle v-bind with object
2 parents 78cb4fc + 3917b04 commit 36661b4

File tree

9 files changed

+24
-5
lines changed

9 files changed

+24
-5
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [0.1.2] - 2020-05-11
10+
11+
### Changed
12+
13+
- Support using `v-bind` to pass an object, as in `v-bind:$attrs`.
14+
- The `hasContent` check should be assume slots will have content.
15+
916
## [0.1.1] - 2020-04-27
1017

1118
### Changed
@@ -19,6 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1926

2027
- Initial release 🎉.
2128

22-
[unreleased]: https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/compare/v0.1.1...HEAD
29+
[unreleased]: https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/compare/v0.1.2...HEAD
30+
[0.1.2]: https://github.com/CultureHQ/components/compare/v0.1.1...v0.1.2
2331
[0.1.1]: https://github.com/CultureHQ/components/compare/v0.1.0...v0.1.1
2432
[0.1.0]: https://github.com/CultureHQ/components/compare/9de449...v0.1.0

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ makeRuleTester("anchor-has-content", rule, {
77
"<a is='TextWrapper' />",
88
"<a v-text='msg' />",
99
"<a v-html='msg' />",
10+
"<a><slot /></a>",
1011
"<Anchor />"
1112
],
1213
invalid: [

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ makeRuleTester("heading-has-content", rule, {
77
"<h1><span>test</span></h1>",
88
"<h1 v-text='msg'></h1>",
99
"<h1 v-html='msg'></h1>",
10-
"<h1>{{ test }}</h1>"
10+
"<h1>{{ test }}</h1>",
11+
"<h1><slot /></h1>"
1112
],
1213
invalid: [
1314
"<h1 />",

src/utils/getAttributeName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const getAttributeName = (node) => {
44
if (!node.directive) {
55
return key.name;
66
}
7-
return key.name.name === "bind" && key.argument.name;
7+
return key.name.name === "bind" && key.argument && key.argument.name;
88
};
99

1010
module.exports = getAttributeName;

src/utils/getElementAttribute.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const getElementAttribute = (node, name) => {
66
(!attribute.directive && key.name === name) ||
77
(attribute.directive &&
88
key.name.name === "bind" &&
9+
key.argument &&
910
key.argument.name === name)
1011
) {
1112
return attribute;

src/utils/getLiteralAttributeValue.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const getLiteralAttributeValue = (node, name) => {
99
if (
1010
attribute.directive &&
1111
key.name.name === "bind" &&
12+
key.argument &&
1213
key.argument.name === name &&
1314
value &&
1415
value.expression &&

src/utils/hasAccessibleChild.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const hasAccessibleChild = (node) =>
66
case "VText":
77
return child.value.trim().length > 0;
88
case "VElement":
9-
return !isHiddenFromScreenReader(child) && hasAccessibleChild(child);
9+
return (
10+
child.rawName === "slot" ||
11+
(!isHiddenFromScreenReader(child) && hasAccessibleChild(child))
12+
);
1013
case "VExpressionContainer":
1114
if (child.expression && child.expression.type === "Identifier") {
1215
return child.expression.name !== "undefined";

src/utils/hasOnDirective.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const hasOnDirective = (node, name) =>
55
return (
66
attribute.directive &&
77
key.name.name === "on" &&
8+
key.argument &&
89
key.argument.name === name &&
910
value &&
1011
value.expression &&

src/utils/isAttribute.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const isAttribute = (node, name) => {
33

44
return (
55
(!node.directive && key.name === name) ||
6-
(node.directive && key.name.name === "bind" && key.argument.name === name)
6+
(node.directive &&
7+
key.name.name === "bind" &&
8+
key.argument &&
9+
key.argument.name === name)
710
);
811
};
912

0 commit comments

Comments
 (0)