File tree 2 files changed +22
-3
lines changed
2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -126,8 +126,8 @@ class Tree extends React.Component {
126
126
newState . expandedKeys = expandedKeys ;
127
127
}
128
128
129
- const checkedKeys = nextProps . checkedKeys !== props . checkedKeys ?
130
- this . calcCheckedKeys ( nextProps , true ) : undefined ;
129
+ const checkedKeys = nextProps . checkedKeys !== props . checkedKeys || props . loadData ?
130
+ this . calcCheckedKeys ( nextProps , true ) : undefined ;
131
131
if ( checkedKeys ) {
132
132
newState . checkedKeys = checkedKeys . checkedKeys ;
133
133
newState . halfCheckedKeys = checkedKeys . halfCheckedKeys ;
@@ -478,7 +478,8 @@ class Tree extends React.Component {
478
478
return { checkedKeys : [ ] , halfCheckedKeys : [ ] } ;
479
479
}
480
480
481
- let checkedKeys = props . checkedKeys || ( isNotInit ? undefined : props . defaultCheckedKeys ) ;
481
+ let checkedKeys = props . checkedKeys ||
482
+ ( isNotInit && ! props . loadData ? undefined : props . defaultCheckedKeys ) ;
482
483
if ( ! checkedKeys ) {
483
484
return undefined ;
484
485
}
Original file line number Diff line number Diff line change @@ -317,6 +317,24 @@ describe('Tree', () => {
317
317
expect ( checkedKeys ) . toEqual ( [ '0-0-1' , '0-0-2' , '0-0-3' , '0-0' ] ) ;
318
318
} ) ;
319
319
320
+ it ( 'check dynamic children when their parent is checked' , ( ) => {
321
+ function mockLoadData ( ) { }
322
+ const wrapper = mount (
323
+ < Tree checkable defaultCheckedKeys = { [ '0-0' ] } loadData = { mockLoadData } >
324
+ < TreeNode title = "parent 1" key = "0-0" />
325
+ </ Tree >
326
+ ) ;
327
+ wrapper . setProps ( {
328
+ children : (
329
+ < TreeNode title = "parent 1" key = "0-0" >
330
+ < TreeNode title = "leaf 1" key = "0-0-0" />
331
+ < TreeNode title = "leaf 2" key = "0-0-1" />
332
+ </ TreeNode >
333
+ ) ,
334
+ } ) ;
335
+ expect ( wrapper . state ( 'checkedKeys' ) ) . toEqual ( [ '0-0-0' , '0-0-1' , '0-0' ] ) ;
336
+ } ) ;
337
+
320
338
describe ( 'strictly' , ( ) => {
321
339
it ( 'checks strictly' , ( ) => {
322
340
const wrapper = mount (
You can’t perform that action at this time.
0 commit comments