@@ -10,6 +10,7 @@ import LegacyContext from './LegacyContext';
10
10
import TreeSelectContext from './TreeSelectContext' ;
11
11
import type { Key , SafeKey } from './interface' ;
12
12
import { getAllKeys , isCheckDisabled } from './utils/valueUtil' ;
13
+ import { flattenTreeData } from 'rc-tree/lib/utils/treeUtil' ;
13
14
14
15
const HIDDEN_STYLE = {
15
16
width : 0 ,
@@ -76,7 +77,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
76
77
( prev , next ) => next [ 0 ] && prev [ 1 ] !== next [ 1 ] ,
77
78
) ;
78
79
79
- // ========================== Active Key Effect ==========================
80
+ // ========================== Active Key ==========================
80
81
const [ activeKey , setActiveKey ] = React . useState < Key > ( null ) ;
81
82
const activeEntity = keyEntities [ activeKey as SafeKey ] ;
82
83
@@ -161,31 +162,24 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
161
162
nodes : EventDataNode < any > [ ] ,
162
163
searchVal ?: string ,
163
164
) : EventDataNode < any > | null => {
164
- const findNode = ( nodeList : EventDataNode < any > [ ] ) : EventDataNode < any > | null => {
165
- for ( const node of nodeList ) {
166
- if ( node . disabled || node . selectable === false ) {
167
- continue ;
168
- }
169
-
170
- if ( searchVal ) {
171
- if ( filterTreeNode ( node ) ) {
172
- return node ;
173
- }
174
- } else if ( ! node . disabled && node . selectable !== false ) {
175
- return node ;
176
- }
165
+ // Flatten the tree structure
166
+ const flattenedNodes = flattenTreeData ( nodes , true , fieldNames ) ;
167
+
168
+ // Iterate through the flattened array to find the first matching node
169
+ const matchedNode = flattenedNodes . find ( node => {
170
+ const rawNode = node . data as EventDataNode < any > ;
171
+ if ( rawNode . disabled || rawNode . selectable === false ) {
172
+ return false ;
173
+ }
177
174
178
- if ( node [ fieldNames . children ] ) {
179
- const matchInChildren = findNode ( node [ fieldNames . children ] ) ;
180
- if ( matchInChildren ) {
181
- return matchInChildren ;
182
- }
183
- }
175
+ if ( searchVal ) {
176
+ return filterTreeNode ( rawNode ) ;
184
177
}
185
- return null ;
186
- } ;
187
178
188
- return findNode ( nodes ) ;
179
+ return true ;
180
+ } ) ;
181
+
182
+ return matchedNode ? ( matchedNode . data as EventDataNode < any > ) : null ;
189
183
} ;
190
184
191
185
// ========================== Active Key Effect ==========================
0 commit comments