@@ -32,10 +32,12 @@ export const SelectPickerTextArea = ({
3232 maxHeight,
3333 refVar,
3434 dependentRefs,
35+ filterOption : filterOptionProp ,
3536 ...props
3637} : SelectPickerTextAreaProps ) => {
3738 // STATES
3839 const [ inputValue , setInputValue ] = useState ( ( value as SingleValue < SelectPickerOptionType < string > > ) ?. value || '' )
40+ const [ isInputDirty , setIsInputDirty ] = useState ( false )
3941
4042 // REFS
4143 const selectRef = useRef < SelectInstance < SelectPickerOptionType < string > > > ( null )
@@ -50,6 +52,7 @@ export const SelectPickerTextArea = ({
5052 useEffect ( ( ) => {
5153 const selectValue = value as SingleValue < SelectPickerOptionType < string > >
5254 setInputValue ( selectValue ?. value || '' )
55+ setIsInputDirty ( false )
5356 } , [ value ] )
5457
5558 // METHODS
@@ -120,9 +123,23 @@ export const SelectPickerTextArea = ({
120123 return false
121124 }
122125
126+ const filterOption : SelectPickerTextAreaProps [ 'filterOption' ] = ( ...filterOptionArgs ) => {
127+ if ( ! isInputDirty ) {
128+ return true
129+ }
130+
131+ if ( filterOptionProp ) {
132+ return filterOptionProp ( ...filterOptionArgs )
133+ }
134+
135+ const [ option , rawInput ] = filterOptionArgs
136+ return option . label . toLowerCase ( ) . includes ( rawInput . toLowerCase ( ) )
137+ }
138+
123139 const onInputChange = ( newValue : string , { action } : InputActionMeta ) => {
124140 if ( action === ReactSelectInputAction . inputChange ) {
125141 setInputValue ( newValue )
142+ setIsInputDirty ( true )
126143
127144 if ( ! newValue ) {
128145 onChange ?.( null , {
@@ -137,6 +154,7 @@ export const SelectPickerTextArea = ({
137154 const selectValue = value as SingleValue < SelectPickerOptionType < string > >
138155 // Reverting input to previously selected value in case of blur event. (no-selection)
139156 setInputValue ( selectValue ?. value || '' )
157+ setIsInputDirty ( false )
140158 }
141159 }
142160
@@ -195,6 +213,7 @@ export const SelectPickerTextArea = ({
195213 selectRef = { selectRef }
196214 inputValue = { inputValue }
197215 value = { value }
216+ filterOption = { filterOption }
198217 onInputChange = { onInputChange }
199218 controlShouldRenderValue = { false }
200219 onChange = { onChange }
0 commit comments