@@ -30,6 +30,7 @@ import { ReactComponent as ICInfoFilledOverride } from '@Icons/ic-info-filled-ov
30
30
import { ComponentSizeType } from '@Shared/constants'
31
31
import { ConditionalWrap } from '@Common/Helper'
32
32
import Tippy from '@tippyjs/react'
33
+ import { isNullOrUndefined } from '@Shared/Helpers'
33
34
import { getCommonSelectStyle , getSelectPickerOptionByValue } from './utils'
34
35
import {
35
36
SelectPickerMultiValueLabel ,
@@ -208,8 +209,6 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
208
209
fullWidth = false ,
209
210
customSelectedOptionsCount = null ,
210
211
renderMenuListFooter,
211
- inputValue,
212
- onInputChange,
213
212
isCreatable = false ,
214
213
onCreateOption,
215
214
closeMenuOnSelect = false ,
@@ -218,6 +217,8 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
218
217
...props
219
218
} : SelectPickerProps < OptionValue , IsMulti > ) => {
220
219
const [ isFocussed , setIsFocussed ] = useState ( false )
220
+ const [ inputValue , setInputValue ] = useState ( '' )
221
+
221
222
const {
222
223
inputId,
223
224
required,
@@ -331,6 +332,15 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
331
332
}
332
333
}
333
334
335
+ const handleInputChange : ReactSelectProps [ 'onInputChange' ] = ( updatedInputValue , actionMeta ) => {
336
+ // If onInputChange is provided, then the input state should be controlled externally
337
+ if ( props . onInputChange ) {
338
+ props . onInputChange ( updatedInputValue , actionMeta )
339
+ return
340
+ }
341
+ setInputValue ( updatedInputValue )
342
+ }
343
+
334
344
const handleKeyDown : ReactSelectProps [ 'onKeyDown' ] = ( e ) => {
335
345
// Prevent the option from being selected if meta or control key is pressed
336
346
if ( ( e . metaKey || e . ctrlKey ) && e . key === 'Enter' ) {
@@ -349,6 +359,15 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
349
359
props . onBlur ?.( e )
350
360
}
351
361
362
+ const handleChange : ReactSelectProps < SelectPickerOptionType < OptionValue > , IsMulti > [ 'onChange' ] = ( ...params ) => {
363
+ // Retain the input value on selection change
364
+ if ( isMulti && isNullOrUndefined ( props . inputValue ) ) {
365
+ setInputValue ( inputValue )
366
+ }
367
+
368
+ props . onChange ?.( ...params )
369
+ }
370
+
352
371
const commonProps = useMemo (
353
372
( ) => ( {
354
373
name : name || inputId ,
@@ -435,14 +454,15 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
435
454
createOptionPosition = "first"
436
455
onCreateOption = { handleCreateOption }
437
456
renderMenuListFooter = { ! optionListError && renderMenuListFooter }
438
- inputValue = { inputValue }
439
- onInputChange = { onInputChange }
457
+ inputValue = { props . inputValue ?? inputValue }
458
+ onInputChange = { handleInputChange }
440
459
icon = { icon }
441
460
showSelectedOptionIcon = { shouldShowSelectedOptionIcon }
442
461
onKeyDown = { handleKeyDown }
443
462
customDisplayText = { customDisplayText }
444
463
onFocus = { handleFocus }
445
464
onBlur = { handleBlur }
465
+ onChange = { handleChange }
446
466
controlShouldRenderValue = { controlShouldRenderValue }
447
467
/>
448
468
</ div >
0 commit comments