Skip to content

[Feature Request] onCheck/onClick/onExpand returns object w/ same data provided at invocation #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/js/NodeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class NodeModel {
disabled: this.getDisabledState(node, parent, disabled, noCascade),
treeDepth: depth,
index,
extraKeys: Object.entries(node)
.filter(([key]) => !CheckModel.flatKeys.includes(key))
.reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}),
};
this.flattenNodes(node.children, node, depth + 1);
});
Expand Down
14 changes: 14 additions & 0 deletions src/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ const CheckModel = {
ALL: 'all',
PARENT: 'parent',
LEAF: 'leaf',
flatKeys: [
'label',
'value',
'children',
'parent',
'isChild',
'isParent',
'isLeaf',
'showCheckbox',
'disabled',
'treeDepth',
'index',
'extraKeys',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we actually should remove this line. Wasn't able to test this locally. Was getting an error on npm run examples and npm run test had some tests that appeared to be failing for me on the master branch w/o my changes.

Suggested change
'extraKeys',

],
};

export default { CheckModel };
9 changes: 8 additions & 1 deletion test/CheckboxTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,9 @@ describe('<CheckboxTree />', () => {
{
value: 'jupiter',
label: 'Jupiter',
test1: '123',
children: [
{ value: 'io', label: 'Io' },
{ value: 'io', label: 'Io', test2: '456' },
{ value: 'europa', label: 'Europa' },
],
},
Expand All @@ -884,6 +885,9 @@ describe('<CheckboxTree />', () => {
treeDepth: 1,
index: 0,
parentValue: 'jupiter',
extraKeys: {
test2: '456',
},
};
const expectedParentMetadata = {
value: 'jupiter',
Expand All @@ -893,6 +897,9 @@ describe('<CheckboxTree />', () => {
treeDepth: 0,
index: 0,
parentValue: undefined,
extraKeys: {
test1: '123',
},
};

// onCheck
Expand Down