@@ -85,7 +85,7 @@ const TreeView = ({
85
85
onLoadData,
86
86
onTreeClick,
87
87
} : ITreeProps ) => {
88
- const [ expandKeys , setExpandKeys ] = useState < string [ ] > ( [ ] ) ;
88
+ const [ expandKeys , setExpandKeys ] = useState < UniqueId [ ] > ( [ ] ) ;
89
89
const [ activeKey , setActiveKey ] = useState < string | null > ( null ) ;
90
90
const loadDataCache = useRef < Record < string , boolean > > ( { } ) ;
91
91
const [ loadingKeys , setLoadingKeys ] = useState < string [ ] > ( [ ] ) ;
@@ -125,15 +125,16 @@ const TreeView = ({
125
125
} ;
126
126
127
127
const handleExpandKey = ( key : string , node : ITreeNodeItemProps ) => {
128
- const index = expandKeys . findIndex ( ( e ) => e === key ) ;
128
+ const nextExpandKeys = ( controlExpandKeys || expandKeys ) . concat ( ) ;
129
+ const index = nextExpandKeys . findIndex ( ( e ) => e === key ) ;
129
130
if ( index > - 1 ) {
130
- expandKeys . splice ( index , 1 ) ;
131
+ nextExpandKeys . splice ( index , 1 ) ;
131
132
} else {
132
- expandKeys . push ( key ) ;
133
+ nextExpandKeys . push ( key ) ;
133
134
}
134
135
onExpand
135
- ? onExpand ( expandKeys . concat ( ) , node )
136
- : setExpandKeys ( expandKeys . concat ( ) ) ;
136
+ ? onExpand ( nextExpandKeys . concat ( ) , node )
137
+ : setExpandKeys ( nextExpandKeys . concat ( ) ) ;
137
138
} ;
138
139
139
140
const handleNodeClick = (
@@ -415,7 +416,7 @@ const TreeView = ({
415
416
return node . id . toString ( ) ;
416
417
} ) ;
417
418
const nextExpandKeys = Array . from (
418
- new Set ( [ ...keys , ...expandKeys ] )
419
+ new Set ( [ ...keys , ...( controlExpandKeys || expandKeys ) ] )
419
420
) ;
420
421
421
422
onExpand
0 commit comments