@@ -157,14 +157,15 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
157
157
}
158
158
} , [ searchValue ] ) ;
159
159
160
- // ========================== Get First Selectable Node ==========================
161
- const getFirstMatchingNode = (
162
- nodes : EventDataNode < any > [ ] ,
163
- searchVal ?: string ,
164
- ) : EventDataNode < any > | null => {
165
- const flattenedNodes = flattenTreeData ( nodes , mergedExpandedKeys , fieldNames ) ;
160
+ // ========================== Flatten Tree Data ==========================
161
+ const flattenedTreeData = React . useMemo ( ( ) => {
162
+ const expandKeys = searchValue ? true : mergedExpandedKeys ;
163
+ return flattenTreeData ( memoTreeData , expandKeys , fieldNames ) ;
164
+ } , [ memoTreeData , searchValue , mergedExpandedKeys ] ) ;
166
165
167
- const matchedNode = flattenedNodes . find ( node => {
166
+ // ========================== Get First Selectable Node ==========================
167
+ const getFirstMatchingNode = ( searchVal ?: string ) : EventDataNode < any > | null => {
168
+ const matchedNode = flattenedTreeData . find ( node => {
168
169
const rawNode = node . data as EventDataNode < any > ;
169
170
if ( rawNode . disabled || rawNode . selectable === false ) {
170
171
return false ;
@@ -189,7 +190,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
189
190
190
191
// Prioritize activating the searched node
191
192
if ( searchValue ) {
192
- const firstNode = getFirstMatchingNode ( memoTreeData , searchValue ) ;
193
+ const firstNode = getFirstMatchingNode ( searchValue ) ;
193
194
setActiveKey ( firstNode ? firstNode [ fieldNames . value ] : null ) ;
194
195
return ;
195
196
}
@@ -201,7 +202,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
201
202
}
202
203
203
204
// If no search value and no checked nodes, activate the first node
204
- const firstNode = getFirstMatchingNode ( memoTreeData , '' ) ;
205
+ const firstNode = getFirstMatchingNode ( ) ;
205
206
setActiveKey ( firstNode ? firstNode [ fieldNames . value ] : null ) ;
206
207
} , [ open , searchValue ] ) ;
207
208
0 commit comments