File tree Expand file tree Collapse file tree 2 files changed +51
-9
lines changed Expand file tree Collapse file tree 2 files changed +51
-9
lines changed Original file line number Diff line number Diff line change @@ -75,15 +75,16 @@ class DropdownTreeSelect extends Component {
75
75
rootPrefixId : this . clientId ,
76
76
searchPredicate,
77
77
} )
78
- // Restore focus-state
79
- const currentFocusNode = this . state . currentFocus && this . treeManager . getNodeById ( this . state . currentFocus )
80
- if ( currentFocusNode ) {
81
- currentFocusNode . _focused = true
82
- }
83
- this . setState ( prevState => ( {
84
- showDropdown : / i n i t i a l | a l w a y s / . test ( showDropdown ) || prevState . showDropdown === true ,
85
- ...this . treeManager . getTreeAndTags ( ) ,
86
- } ) )
78
+ this . setState ( prevState => {
79
+ const currentFocusNode = prevState . currentFocus && this . treeManager . getNodeById ( prevState . currentFocus )
80
+ if ( currentFocusNode ) {
81
+ currentFocusNode . _focused = true
82
+ }
83
+ return {
84
+ showDropdown : / i n i t i a l | a l w a y s / . test ( showDropdown ) || prevState . showDropdown === true ,
85
+ ...this . treeManager . getTreeAndTags ( ) ,
86
+ }
87
+ } )
87
88
}
88
89
89
90
resetSearchState = ( ) => {
Original file line number Diff line number Diff line change @@ -316,3 +316,44 @@ test('appends selected tags to aria-labelledby with text label', t => {
316
316
t . deepEqual ( wrapper . find ( '.dropdown-trigger' ) . prop ( 'aria-labelledby' ) , 'rdts_trigger rdts-0_tag' )
317
317
t . deepEqual ( wrapper . find ( '.dropdown-trigger' ) . prop ( 'aria-label' ) , 'hello world' )
318
318
} )
319
+
320
+ test ( 'select correct focused node when using external state data container' , t => {
321
+ let data = [
322
+ {
323
+ label : 'All data' ,
324
+ value : '0' ,
325
+ checked : false ,
326
+ } ,
327
+ {
328
+ label : 'iWay' ,
329
+ value : '1' ,
330
+ checked : false ,
331
+ } ,
332
+ ]
333
+ const wrapper = mount ( < DropdownTreeSelect id = { dropdownId } data = { data } /> )
334
+ const nodeAllData = {
335
+ _id : `${ dropdownId } -0` ,
336
+ _depth : 0 ,
337
+ label : 'All data' ,
338
+ value : '0' ,
339
+ children : undefined ,
340
+ actions : [ action ] ,
341
+ }
342
+ wrapper . instance ( ) . onCheckboxChange ( nodeAllData . _id , true )
343
+ //simulate external change to the data props.
344
+ wrapper . setProps ( {
345
+ data : [
346
+ {
347
+ label : 'All data' ,
348
+ value : '0' ,
349
+ checked : true ,
350
+ } ,
351
+ {
352
+ label : 'iWay' ,
353
+ value : '1' ,
354
+ checked : false ,
355
+ } ,
356
+ ] ,
357
+ } )
358
+ t . deepEqual ( wrapper . state ( ) . currentFocus , nodeAllData . _id )
359
+ } )
You can’t perform that action at this time.
0 commit comments