@@ -92,53 +92,6 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
92
92
} ;
93
93
} , [ checkable , checkedKeys , halfCheckedKeys ] ) ;
94
94
95
- // ========================== Get First Selectable Node ==========================
96
- const getFirstMatchingNode = (
97
- nodes : EventDataNode < any > ,
98
- predicate : ( node : EventDataNode < any > ) => boolean ,
99
- ) : EventDataNode < any > | null => {
100
- for ( const node of nodes ) {
101
- if ( predicate ( node ) ) {
102
- return node ;
103
- }
104
- if ( node [ fieldNames . children ] ) {
105
- const matchInChildren = getFirstMatchingNode ( node [ fieldNames . children ] , predicate ) ;
106
- if ( matchInChildren ) {
107
- return matchInChildren ;
108
- }
109
- }
110
- }
111
- return null ;
112
- } ;
113
-
114
- const getFirstSelectableNode = ( nodes : EventDataNode < any > ) : EventDataNode < any > | null =>
115
- getFirstMatchingNode ( nodes , node => node . selectable !== false && ! node . disabled ) ;
116
-
117
- const getFirstMatchNode = ( nodes : EventDataNode < any > ) : EventDataNode < any > | null =>
118
- getFirstMatchingNode ( nodes , node => filterTreeNode ( node ) && ! node . disabled ) ;
119
-
120
- // ========================== Active Key Effect ==========================
121
- React . useEffect ( ( ) => {
122
- if ( searchValue ) {
123
- const firstMatchNode = getFirstMatchNode ( memoTreeData ) ;
124
- setActiveKey ( firstMatchNode ? firstMatchNode [ fieldNames . value ] : null ) ;
125
- return ;
126
- }
127
-
128
- if ( open ) {
129
- if ( ! multiple && checkedKeys . length ) {
130
- setActiveKey ( checkedKeys [ 0 ] ) ;
131
- } else {
132
- const firstSelectableNode = getFirstSelectableNode ( memoTreeData ) ;
133
- if ( firstSelectableNode ) {
134
- setActiveKey ( firstSelectableNode [ fieldNames . value ] ) ;
135
- }
136
- }
137
- return ;
138
- }
139
- setActiveKey ( null ) ;
140
- } , [ open , searchValue ] ) ;
141
-
142
95
// ========================== Scroll Effect ==========================
143
96
React . useEffect ( ( ) => {
144
97
if ( open && ! multiple && checkedKeys . length ) {
@@ -203,6 +156,53 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
203
156
}
204
157
} , [ searchValue ] ) ;
205
158
159
+ // ========================== Get First Selectable Node ==========================
160
+ const getFirstMatchingNode = (
161
+ nodes : EventDataNode < any > ,
162
+ predicate : ( node : EventDataNode < any > ) => boolean ,
163
+ ) : EventDataNode < any > | null => {
164
+ for ( const node of nodes ) {
165
+ if ( predicate ( node ) ) {
166
+ return node ;
167
+ }
168
+ if ( node [ fieldNames . children ] ) {
169
+ const matchInChildren = getFirstMatchingNode ( node [ fieldNames . children ] , predicate ) ;
170
+ if ( matchInChildren ) {
171
+ return matchInChildren ;
172
+ }
173
+ }
174
+ }
175
+ return null ;
176
+ } ;
177
+
178
+ const getFirstSelectableNode = ( nodes : EventDataNode < any > ) : EventDataNode < any > | null =>
179
+ getFirstMatchingNode ( nodes , node => node . selectable !== false && ! node . disabled ) ;
180
+
181
+ const getFirstMatchNode = ( nodes : EventDataNode < any > ) : EventDataNode < any > | null =>
182
+ getFirstMatchingNode ( nodes , node => filterTreeNode ( node ) && ! node . disabled ) ;
183
+
184
+ // ========================== Active Key Effect ==========================
185
+ React . useEffect ( ( ) => {
186
+ if ( searchValue ) {
187
+ const firstMatchNode = getFirstMatchNode ( memoTreeData ) ;
188
+ setActiveKey ( firstMatchNode ? firstMatchNode [ fieldNames . value ] : null ) ;
189
+ return ;
190
+ }
191
+
192
+ if ( open ) {
193
+ if ( ! multiple && checkedKeys . length ) {
194
+ setActiveKey ( checkedKeys [ 0 ] ) ;
195
+ } else {
196
+ const firstSelectableNode = getFirstSelectableNode ( memoTreeData ) ;
197
+ if ( firstSelectableNode ) {
198
+ setActiveKey ( firstSelectableNode [ fieldNames . value ] ) ;
199
+ }
200
+ }
201
+ return ;
202
+ }
203
+ setActiveKey ( null ) ;
204
+ } , [ open , searchValue ] ) ;
205
+
206
206
// ========================= Keyboard =========================
207
207
React . useImperativeHandle ( ref , ( ) => ( {
208
208
scrollTo : treeRef . current ?. scrollTo ,
0 commit comments