@@ -102,21 +102,6 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
102
102
// eslint-disable-next-line react-hooks/exhaustive-deps
103
103
} , [ open ] ) ;
104
104
105
- // =========================== Search Effect ===========================
106
- React . useEffect ( ( ) => {
107
- if ( searchValue ) {
108
- setSearchExpandedKeys ( getAllKeys ( treeData , fieldNames ) ) ;
109
-
110
- const firstMatchNode = getFirstMatchNode ( memoTreeData ) ;
111
- if ( firstMatchNode ) {
112
- setActiveKey ( firstMatchNode [ fieldNames . value ] ) ;
113
- } else {
114
- setActiveKey ( null ) ;
115
- }
116
- }
117
- // eslint-disable-next-line react-hooks/exhaustive-deps
118
- } , [ searchValue ] ) ;
119
-
120
105
// ========================== Events ==========================
121
106
const onListMouseDown : React . MouseEventHandler < HTMLDivElement > = event => {
122
107
event . preventDefault ( ) ;
@@ -138,21 +123,6 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
138
123
}
139
124
} ;
140
125
141
- const getFirstMatchNode = ( nodes : EventDataNode < any > ) : EventDataNode < any > | null => {
142
- for ( const node of nodes ) {
143
- if ( filterTreeNode ( node ) && ! node . disabled ) {
144
- return node ;
145
- }
146
- if ( node [ fieldNames . children ] ) {
147
- const matchInChildren = getFirstMatchNode ( node [ fieldNames . children ] ) ;
148
- if ( matchInChildren ) {
149
- return matchInChildren ;
150
- }
151
- }
152
- }
153
- return null ;
154
- } ;
155
-
156
126
// ========================== Search ==========================
157
127
const lowerSearchValue = String ( searchValue ) . toLowerCase ( ) ;
158
128
const filterTreeNode = ( treeNode : EventDataNode < any > ) => {
@@ -182,6 +152,36 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
182
152
}
183
153
} ;
184
154
155
+ const getFirstMatchNode = ( nodes : EventDataNode < any > ) : EventDataNode < any > | null => {
156
+ for ( const node of nodes ) {
157
+ if ( filterTreeNode ( node ) && ! node . disabled ) {
158
+ return node ;
159
+ }
160
+ if ( node [ fieldNames . children ] ) {
161
+ const matchInChildren = getFirstMatchNode ( node [ fieldNames . children ] ) ;
162
+ if ( matchInChildren ) {
163
+ return matchInChildren ;
164
+ }
165
+ }
166
+ }
167
+ return null ;
168
+ } ;
169
+
170
+ // =========================== Search Effect ===========================
171
+ React . useEffect ( ( ) => {
172
+ if ( searchValue ) {
173
+ setSearchExpandedKeys ( getAllKeys ( treeData , fieldNames ) ) ;
174
+
175
+ const firstMatchNode = getFirstMatchNode ( memoTreeData ) ;
176
+ if ( firstMatchNode ) {
177
+ setActiveKey ( firstMatchNode [ fieldNames . value ] ) ;
178
+ } else {
179
+ setActiveKey ( null ) ;
180
+ }
181
+ }
182
+ // eslint-disable-next-line react-hooks/exhaustive-deps
183
+ } , [ searchValue ] ) ;
184
+
185
185
// ========================= Keyboard =========================
186
186
React . useImperativeHandle ( ref , ( ) => ( {
187
187
scrollTo : treeRef . current ?. scrollTo ,
0 commit comments