1- import { lazy , Suspense , useCallback , memo , forwardRef , ComponentType , ReactNode } from 'react' ;
1+ import { lazy , Suspense , useCallback , memo , ComponentType , ReactNode , forwardRef , useRef , useImperativeHandle } from 'react' ;
22import type { Props as ReactSelectProps , GroupBase , StylesConfig , MultiValueProps , PlaceholderProps } from 'react-select' ;
33const Select = lazy ( ( ) => import ( 'react-select' ) ) as unknown as typeof import ( 'react-select' ) . default ;
44const CreatableSelect = lazy ( ( ) => import ( 'react-select/creatable' ) ) as unknown as typeof import ( 'react-select/creatable' ) . default ;
@@ -59,6 +59,11 @@ interface IconConfig {
5959 [ key : string ] : unknown ;
6060}
6161
62+ interface EnhancedSelectRef {
63+ inputRef ?: { blur : ( ) => void } | null ;
64+ [ key : string ] : unknown ;
65+ }
66+
6267interface EnhancedSelectProps extends Omit < ReactSelectProps < EnhancedSelectOption , boolean , GroupBase < EnhancedSelectOption > > , 'options' | 'formatOptionLabel' > {
6368 // Enhanced functionality
6469 enableTags ?: boolean ;
@@ -84,7 +89,7 @@ interface EnhancedSelectProps extends Omit<ReactSelectProps<EnhancedSelectOption
8489 components ?: Record < string , ComponentType < unknown > > ;
8590}
8691
87- const EnhancedSelect = forwardRef < HTMLDivElement , EnhancedSelectProps > ( ( {
92+ const EnhancedSelect = forwardRef < EnhancedSelectRef , EnhancedSelectProps > ( ( {
8893 // Enhanced functionality props
8994 enableTags = false ,
9095 enableIcons = false ,
@@ -111,7 +116,14 @@ const EnhancedSelect = forwardRef<HTMLDivElement, EnhancedSelectProps>(({
111116 styles : customStyles ,
112117 inputId,
113118 ...selectProps
114- } , ref ) => {
119+ } , forwardedRef ) => {
120+ // Ref to the internal select component
121+ const selectRef = useRef < { inputRef ?: { blur : ( ) => void } | null } > ( null ) ;
122+
123+ // Expose select API through imperative handle
124+ useImperativeHandle ( forwardedRef , ( ) => ( {
125+ inputRef : selectRef . current ?. inputRef
126+ } ) , [ ] ) ;
115127
116128 // Internal formatOptionLabel that handles enhanced features
117129 const internalFormatOptionLabel = useCallback ( ( option : EnhancedSelectOption , { context } : { context : 'menu' | 'value' } ) => {
@@ -227,7 +239,7 @@ const EnhancedSelect = forwardRef<HTMLDivElement, EnhancedSelectProps>(({
227239 ...enhancedStyles ,
228240 ...customStyles ,
229241 // Merge functions for overlapping style keys
230- ...( customStyles && Object . keys ( customStyles ) . reduce < Record < string , unknown > > ( ( acc , key ) => {
242+ ...( customStyles ? Object . keys ( customStyles ) . reduce < Record < string , unknown > > ( ( acc , key ) => {
231243 const styleKey = key as keyof StylesConfig < EnhancedSelectOption , boolean , GroupBase < EnhancedSelectOption > > ;
232244 const enhancedStyleFn = enhancedStyles [ styleKey ] ;
233245 const customStyleFn = customStyles [ styleKey ] ;
@@ -238,13 +250,13 @@ const EnhancedSelect = forwardRef<HTMLDivElement, EnhancedSelectProps>(({
238250 } ;
239251 }
240252 return acc ;
241- } , { } ) )
253+ } , { } ) : { } )
242254 } ;
243255
244256 const selectElement = (
245257 < Suspense fallback = { < div > Loading...</ div > } >
246258 < SelectComponent
247- ref = { ref }
259+ ref = { selectRef as any }
248260 options = { options }
249261 formatOptionLabel = { internalFormatOptionLabel }
250262 components = { components }
0 commit comments