1- import { FC , useMemo } from 'react'
1+ import { FC , useMemo , useState } from 'react'
22import CreatableSelect from 'react-select/creatable'
3+ import { InputActionMeta } from 'react-select'
34import {
45 useGetWarehouseConnectionEventsQuery ,
56 useGetWarehouseConnectionsQuery ,
@@ -33,6 +34,22 @@ const EventNameSelect: FC<EventNameSelectProps> = ({ onChange, value }) => {
3334 )
3435 const options = useMemo ( ( ) => buildEventOptions ( data ?. events ) , [ data ?. events ] )
3536 const showWarning = isSuccess && isUnknownEvent ( value , data ?. events )
37+ const [ inputValue , setInputValue ] = useState ( '' )
38+
39+ // Keep the typed text on blur (react-select discards it by default) so
40+ // clicking outside commits the value instead of clearing it.
41+ const handleInputChange = ( val : string , meta : InputActionMeta ) => {
42+ if ( meta . action === 'input-change' ) setInputValue ( val )
43+ }
44+ const handleChange = ( option : EventOption | null ) => {
45+ setInputValue ( '' )
46+ onChange ( option ?. value ?? '' )
47+ }
48+ const handleBlur = ( ) => {
49+ if ( ! inputValue ) return
50+ onChange ( inputValue )
51+ setInputValue ( '' )
52+ }
3653
3754 return (
3855 < div className = 'event-name-select' >
@@ -42,11 +59,14 @@ const EventNameSelect: FC<EventNameSelectProps> = ({ onChange, value }) => {
4259 classNamePrefix = 'react-select'
4360 isClearable
4461 isLoading = { isLoading }
62+ inputValue = { inputValue }
63+ onInputChange = { handleInputChange }
64+ onBlur = { handleBlur }
4565 maxMenuHeight = { 200 }
4666 menuPlacement = 'auto'
4767 options = { options }
4868 value = { value ? { label : value , value } : null }
49- onChange = { ( option : EventOption | null ) => onChange ( option ?. value ?? '' ) }
69+ onChange = { handleChange }
5070 placeholder = 'e.g. checkout_completed'
5171 formatCreateLabel = { ( input : string ) => `Use "${ input } "` }
5272 noOptionsMessage = { ( ) => 'Type to add a new event' }
0 commit comments