File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -27,10 +27,15 @@ export function treeControllerFromUpdateState<T>(updateState: (f: TreeStateUpdat
27
27
} ) ) ;
28
28
} ;
29
29
obj . toggleExpanded = ( id : string ) => {
30
- obj . updateState ! ( ( { expandedIds, ...rest } ) => ( {
31
- ...rest ,
32
- expandedIds : { ...expandedIds , [ id ] : ! expandedIds || ! expandedIds [ id ] } ,
33
- } ) ) ;
30
+ obj . updateState ! ( ( { expandedIds, ...rest } , { allNodes } ) => {
31
+ const explicitExpandedState = expandedIds ? expandedIds [ id ] : undefined ;
32
+ const isExpanded = ( explicitExpandedState === true )
33
+ || ( allNodes [ id ] && allNodes [ id ] . isActiveTrail && explicitExpandedState === undefined ) ;
34
+ return {
35
+ ...rest ,
36
+ expandedIds : { ...expandedIds , [ id ] : ! isExpanded } ,
37
+ } ;
38
+ } ) ;
34
39
} ;
35
40
obj . setActiveId = ( id : string | null ) => {
36
41
obj . updateState ! ( ( st ) => ( { ...st , activeId : id } ) ) ;
You can’t perform that action at this time.
0 commit comments