Won't cascade down during serialization
ZhangHanwen96 opened this issue · 1 comments
Describe the bug
The root checkbox won't be fully checked if it is in [checked] list .
Reproduction steps
If i were to put 'mars' in checked
list, instead of get fully checked state , it is not checked at all.
const nodes = [
{
value: "mars",
label: "Mars",
children: [
{ value: "phobos", label: "Phobos" },
{ value: "deimos", label: "Deimos" },
{
value: "mars-1",
label: "Mars",
children: [
{ value: "phobos-1", label: "Phobos" },
{ value: "deimos-1", label: "Deimos" }
]
}
]
}
];
class Widget extends React.Component {
state = {
checked: ["mars"],
expanded: []
};
render() {
return (
<>
<CheckboxTree
nodes={nodes}
checked={this.state.checked}
expanded={this.state.expanded}
onCheck={(checked) => this.setState({ checked })}
onExpand={(expanded) => this.setState({ expanded })}
/>
</>
);
}
}
**Expected behavior**
.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**My solution**
```typescript
// Deserialize values and set their nodes to true
listKeys.forEach((listKey) => {
lists[listKey].forEach((value) => {
if (this.flatNodes[value] !== undefined) {
this.flatNodes[value][listKey] = true;
}
if(listKey === 'checked') {
const {noCascade, checkModel} = this.props;
// ----- add cascade down process here -----
this.flatNodes[value].children.forEach((child) => {
this.toggleChecked(child, true, checkModel, noCascade, false);
});
}
});
});
deplicated