@@ -160,27 +160,32 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
160
160
// eslint-disable-next-line react-hooks/exhaustive-deps
161
161
} , [ searchValue ] ) ;
162
162
163
- // ========================== Flatten Tree Data ==========================
164
- const flattenedTreeData = React . useMemo ( ( ) => {
165
- return flattenTreeData ( memoTreeData , mergedExpandedKeys , fieldNames ) ;
166
- } , [ memoTreeData , mergedExpandedKeys ] ) ;
167
-
168
163
// ========================== Get First Selectable Node ==========================
169
- const getFirstMatchingNode = ( searchVal ?: string ) : EventDataNode < any > | null => {
170
- const matchedNode = flattenedTreeData . find ( node => {
171
- const rawNode = node . data as EventDataNode < any > ;
172
- if ( rawNode . disabled || rawNode . selectable === false ) {
173
- return false ;
164
+ const getFirstMatchingNode = (
165
+ nodes : EventDataNode < any > [ ] ,
166
+ searchVal ?: string ,
167
+ ) : EventDataNode < any > | null => {
168
+ for ( const node of nodes ) {
169
+ if ( node . disabled || node . selectable === false ) {
170
+ continue ;
174
171
}
175
172
176
173
if ( searchVal ) {
177
- return filterTreeNode ( rawNode ) ;
174
+ if ( filterTreeNode ( node ) ) {
175
+ return node ;
176
+ }
177
+ } else {
178
+ return node ;
178
179
}
179
180
180
- return true ;
181
- } ) ;
182
-
183
- return matchedNode ? ( matchedNode . data as EventDataNode < any > ) : null ;
181
+ if ( node [ fieldNames . children ] ) {
182
+ const matchInChildren = getFirstMatchingNode ( node [ fieldNames . children ] , searchVal ) ;
183
+ if ( matchInChildren ) {
184
+ return matchInChildren ;
185
+ }
186
+ }
187
+ }
188
+ return null ;
184
189
} ;
185
190
186
191
// ========================== Active Key Effect ==========================
@@ -192,7 +197,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
192
197
193
198
// Prioritize activating the searched node
194
199
if ( searchValue ) {
195
- const firstNode = getFirstMatchingNode ( searchValue ) ;
200
+ const firstNode = getFirstMatchingNode ( treeData , searchValue ) ;
196
201
setActiveKey ( firstNode ? firstNode [ fieldNames . value ] : null ) ;
197
202
return ;
198
203
}
@@ -204,7 +209,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
204
209
}
205
210
206
211
// If no search value and no checked nodes, activate the first node
207
- const firstNode = getFirstMatchingNode ( ) ;
212
+ const firstNode = getFirstMatchingNode ( treeData ) ;
208
213
setActiveKey ( firstNode ? firstNode [ fieldNames . value ] : null ) ;
209
214
} , [ open , searchValue ] ) ;
210
215
0 commit comments