Skip to content

Commit

Permalink
fix(checktreepicker): onChange callback does't return the correct val…
Browse files Browse the repository at this point in the history
…ue (#1710)

feat(test): test
  • Loading branch information
superman66 committed Jun 2, 2021
1 parent 2ebd010 commit 060a43c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/CheckTreePicker/CheckTreePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic

if (isEveryChildChecked(node, this.nodes, this.props)) {
this.nodes[node.refKey].checkAll = true;
this.nodes[node.refKey].check = true;
return CHECK_STATE.CHECK;
}

Expand Down Expand Up @@ -481,6 +482,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
const checkItems = [];
Object.keys(this.nodes).map((refKey: string) => {
const node = this.nodes[refKey];

if (selectedValues.some((value: any) => shallowEqual(node[valueKey], value))) {
checkItems.push(node);
}
Expand Down Expand Up @@ -531,7 +533,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
}

/**
* 过滤选中的values中不包含 uncheckableItemValues 的那些值
* 过滤选中的 values 中不包含 uncheckableItemValues 的那些值
* @param {*} values
*/
filterSelectedValues(values: any[]) {
Expand Down Expand Up @@ -743,7 +745,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
}

toggleNode(key: string, node: Node, toggleValue: boolean) {
// 如果该节点处于 disabledChecbox,则忽略该值
// 如果该节点处于 disabledCheckbox,则忽略该值
if (!node.uncheckable) {
this.nodes[node.refKey][key] = toggleValue;
}
Expand Down
60 changes: 60 additions & 0 deletions src/CheckTreePicker/test/CheckTreePickerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,66 @@ describe('CheckTreePicker', () => {
instance.unmount();
});

it('Should return 2 values', done => {
const customData = [
{
value: '1',
label: '1',
children: [
{
value: '1-1',
label: '1-1'
},
{
value: '1-2',
label: '1-2'
},
{
value: '1-3',
label: '1-3'
}
]
},
{
value: '2',
label: '2',
children: [
{
value: '2-1',
label: '2-1'
},
{
value: '2-2',
label: '2-2'
},
{
value: '2-3',
label: '2-3'
}
]
}
];

const doneOp = values => {
if (values.length === 2) {
done();
}
};
const instance = getDOMNode(
<CheckTreePicker
data={customData}
inline
value={['1-1', '1-2', '1-3']}
cascade
defaultExpandAll
onChange={doneOp}
/>
);

assert.equal(instance.querySelectorAll('.rs-checkbox-checked').length, 4);
ReactTestUtils.Simulate.change(instance.querySelectorAll('.rs-check-tree-node input')[5]);
});

it('Should render empty tree when searchKeyword is `name`', () => {
const instance = mount(<CheckTreePicker data={data} inline searchKeyword="name" />);
assert.equal(instance.find('.rs-check-tree-node').length, 0);
Expand Down

1 comment on commit 060a43c

@vercel
Copy link

@vercel vercel bot commented on 060a43c Jun 2, 2021

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

rsuite – ./docs

rsuite.vercel.app
rsuite-rsuite.vercel.app
rsuitejs.com
rsuite-git-v4-rsuite.vercel.app

Please sign in to comment.