1
1
import * as React from 'react' ;
2
+ import { useEffect } from 'react' ;
2
3
import KeyCode from 'rc-util/lib/KeyCode' ;
3
4
import omit from 'rc-util/lib/omit' ;
4
5
import pickAttrs from 'rc-util/lib/pickAttrs' ;
@@ -140,12 +141,12 @@ const OptionList: React.ForwardRefRenderFunction<
140
141
} ;
141
142
142
143
// Auto active first item when list length or searchValue changed
143
- React . useEffect ( ( ) => {
144
+ useEffect ( ( ) => {
144
145
setActive ( defaultActiveFirstOption !== false ? getEnabledActiveIndex ( 0 ) : - 1 ) ;
145
146
} , [ memoFlattenOptions . length , searchValue ] ) ;
146
147
147
148
// Auto scroll to item position in single mode
148
- React . useEffect ( ( ) => {
149
+ useEffect ( ( ) => {
149
150
/**
150
151
* React will skip `onChange` when component update.
151
152
* `setActive` function will call root accessibility state update which makes re-render.
@@ -157,8 +158,11 @@ const OptionList: React.ForwardRefRenderFunction<
157
158
const index = memoFlattenOptions . findIndex (
158
159
( { data } ) => ( data as OptionData ) . value === value ,
159
160
) ;
160
- setActive ( index ) ;
161
- scrollIntoView ( index ) ;
161
+
162
+ if ( index !== - 1 ) {
163
+ setActive ( index ) ;
164
+ scrollIntoView ( index ) ;
165
+ }
162
166
}
163
167
} ) ;
164
168
@@ -168,7 +172,7 @@ const OptionList: React.ForwardRefRenderFunction<
168
172
}
169
173
170
174
return ( ) => clearTimeout ( timeoutId ) ;
171
- } , [ open ] ) ;
175
+ } , [ open , searchValue ] ) ;
172
176
173
177
// ========================== Values ==========================
174
178
const onSelectValue = ( value : RawValueType ) => {
0 commit comments