Skip to content

Commit c8c0bef

Browse files
authored
Merge pull request #129 from grapoza/fix-child-prop-default
Fixes default children prop behavior
2 parents 0e892a2 + e89ae6e commit c8c0bef

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
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 <[email protected]>",
55
"license": "MIT",
6-
"version": "1.3.0",
6+
"version": "1.3.1",
77
"browser": "index.js",
88
"repository": {
99
"url": "https://github.com/grapoza/vue-tree",

src/components/TreeViewNode.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
return this.model.children.length > 0 && this.model.expandable;
270270
},
271271
childrenPropName() {
272-
return this.childrenPropNames.find(pn => Array.isArray(this.model[pn]));
272+
return this.childrenPropNames.find(pn => Array.isArray(this.model[pn])) || 'children';
273273
},
274274
customClasses() {
275275
return (this.model.customizations || {}).classes || {};
@@ -326,8 +326,8 @@
326326
this.$_treeViewNode_assignDefaultProps(this.modelDefaults, this.model);
327327
328328
// Set expected properties if not provided
329-
if (!Array.isArray(this.model.children)) {
330-
this.$set(this.model, 'children', []);
329+
if (!Array.isArray(this.model[this.childrenPropName])) {
330+
this.$set(this.model, this.childrenPropName, []);
331331
}
332332
if (typeof this.model.expandable !== 'boolean') {
333333
this.$set(this.model, 'expandable', true);

tests/unit/TreeViewNode.spec.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -719,20 +719,38 @@ describe('TreeViewNode.vue', () => {
719719

720720
describe('when childrenPropNames is specified', () => {
721721

722-
beforeEach(() => {
723-
let defaultProps = getDefaultPropsData();
724-
wrapper = createWrapper(Object.assign(defaultProps, {
725-
childrenPropNames: ['nope', 'children'],
726-
initialModel: generateNodes(['sf', ['s', 's']], defaultProps.radioGroupValues)[0]
727-
}));
728-
});
722+
describe('and a valid-children model property is specified', () => {
723+
724+
beforeEach(() => {
725+
let defaultProps = getDefaultPropsData();
726+
wrapper = createWrapper(Object.assign(defaultProps, {
727+
childrenPropNames: ['nope', 'children'],
728+
initialModel: generateNodes(['sf', ['s', 's']], defaultProps.radioGroupValues)[0]
729+
}));
730+
});
731+
732+
it('has a childrenPropName matching the first-avilable valid-children model property', () => {
733+
expect(wrapper.vm.childrenPropName).to.equal('children');
734+
});
729735

730-
it('has a childrenPropName matching the first-avilable valid-children model property', () => {
731-
expect(wrapper.vm.childrenPropName).to.equal('children');
736+
it('has a children list of the first-avilable model[childrenPropName] property', () => {
737+
expect(wrapper.vm.model.children.length).to.equal(2);
738+
});
732739
});
733740

734-
it('has a children list of the first-avilable model[childrenPropName] property', () => {
735-
expect(wrapper.vm.model.children.length).to.equal(2);
741+
describe('and a valid-children model property is not specified', () => {
742+
743+
beforeEach(() => {
744+
let defaultProps = getDefaultPropsData();
745+
wrapper = createWrapper(Object.assign(defaultProps, {
746+
childrenPropNames: ['nope', 'steve'],
747+
initialModel: generateNodes(['sf', ['s', 's']], defaultProps.radioGroupValues)[0]
748+
}));
749+
});
750+
751+
it('has a childrenPropName of "children"', () => {
752+
expect(wrapper.vm.childrenPropName).to.equal('children');
753+
});
736754
});
737755
});
738756
});

0 commit comments

Comments
 (0)