Skip to content

Commit 2d8ab32

Browse files
authored
Merge pull request #133 from grapoza/another-children-fix
Fixes child children prop discovery
2 parents b0ef6a2 + 21dc42b commit 2d8ab32

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Yet another Vue treeview component.",
44
"author": "Gregg Rapoza <grapoza@gmail.com>",
55
"license": "MIT",
6-
"version": "1.3.3",
6+
"version": "1.3.4",
77
"browser": "index.js",
88
"repository": {
99
"url": "https://github.com/grapoza/vue-tree",

src/components/TreeViewNode.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@
318318
$_treeViewNode_getIdPropNameForNode(node) {
319319
return this.idPropNames.find(pn => typeof node[pn] === 'number' || typeof node[pn] === 'string');
320320
},
321+
$_treeViewNode_getChildrenPropNameForNode(node) {
322+
return this.childrenPropNames.find(pn => Array.isArray(node[pn])) || 'children';
323+
},
321324
/*
322325
* Normalizes the data model to the format consumable by TreeViewNode.
323326
*/

src/mixins/TreeViewNodeAria.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export default {
157157
else {
158158
let lastModel = this.model[this.childrenPropName][childIndex - 1];
159159
while (lastModel.children.length > 0 && lastModel.expandable && lastModel.state.expanded) {
160-
lastModel = lastModel.children[lastModel.children.length - 1];
160+
lastModel = lastModel[this.$_treeViewNode_getChildrenPropNameForNode(lastModel)][lastModel.children.length - 1];
161161
}
162162

163163
lastModel.focusable = true;
@@ -169,7 +169,7 @@ export default {
169169
// Otherwise, punt this up to this node's parent
170170
let childIndex = this.model[this.childrenPropName].indexOf(childNode);
171171
if (!ignoreChild && childNode.children.length > 0 && childNode.expandable && childNode.state.expanded) {
172-
childNode.children[0].focusable = true;
172+
childNode[this.$_treeViewNode_getChildrenPropNameForNode(childNode)][0].focusable = true;
173173
}
174174
else if (childIndex < this.model[this.childrenPropName].length - 1) {
175175
this.model[this.childrenPropName][childIndex + 1].focusable = true;

0 commit comments

Comments
 (0)