@@ -8,7 +8,7 @@ import { omit, useEvent } from '@rc-component/util';
88import KeyCode from '@rc-component/util/lib/KeyCode' ;
99import { isValidateOpenKey } from '../utils/keyUtil' ;
1010import clsx from 'clsx' ;
11- import type { FilledComponentsConfig } from '../hooks/useComponents' ;
11+ import type { ComponentsConfig } from '../hooks/useComponents' ;
1212import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode' ;
1313
1414export interface SelectInputRef {
@@ -43,7 +43,7 @@ export interface SelectInputProps extends Omit<React.HTMLAttributes<HTMLDivEleme
4343 className ?: string ;
4444 style ?: React . CSSProperties ;
4545 focused ?: boolean ;
46- components : FilledComponentsConfig ;
46+ components : ComponentsConfig ;
4747}
4848
4949const DEFAULT_OMIT_PROPS = [
@@ -104,19 +104,14 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
104104 // Token handling
105105 tokenWithEnter,
106106
107+ // Components
108+ components,
109+
107110 ...restProps
108111 } = props ;
109112
110- const {
111- triggerOpen,
112- toggleOpen,
113- showSearch,
114- disabled,
115- loading,
116- classNames,
117- styles,
118- autoClearSearchValue,
119- } = useBaseProps ( ) ;
113+ const { triggerOpen, toggleOpen, showSearch, disabled, loading, classNames, styles } =
114+ useBaseProps ( ) ;
120115
121116 const rootRef = React . useRef < HTMLDivElement > ( null ) ;
122117 const inputRef = React . useRef < HTMLInputElement > ( null ) ;
@@ -161,10 +156,10 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
161156 ( ) => ( {
162157 focus : ( options ?: FocusOptions ) => {
163158 // Focus the inner input if available, otherwise fall back to root div.
164- inputRef . current . focus ?.( options ) ;
159+ ( inputRef . current || rootRef . current ) . focus ?.( options ) ;
165160 } ,
166161 blur : ( ) => {
167- inputRef . current . blur ?.( ) ;
162+ ( inputRef . current || rootRef . current ) . blur ?.( ) ;
168163 } ,
169164 nativeElement : rootRef . current ,
170165 } ) ,
@@ -203,6 +198,9 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
203198 onBlur ?.( event ) ;
204199 } ;
205200
201+ // =================== Components ===================
202+ const { root : RootComponent } = components ;
203+
206204 // ===================== Render =====================
207205 const domProps = omit ( restProps , DEFAULT_OMIT_PROPS ) ;
208206
@@ -212,6 +210,31 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
212210 onInputKeyDown : onInternalInputKeyDown ,
213211 } ;
214212
213+ const sharedProps = {
214+ // Open
215+ onMouseDown : onInternalMouseDown ,
216+ onBlur : onInternalBlur ,
217+ } as const ;
218+
219+ if ( RootComponent ) {
220+ if ( React . isValidElement < any > ( RootComponent ) ) {
221+ const oriProps = RootComponent . props || { } ;
222+ return React . cloneElement ( RootComponent , {
223+ ...sharedProps ,
224+ onMouseDown : ( e : React . MouseEvent < HTMLDivElement > ) => {
225+ sharedProps . onMouseDown ( e ) ;
226+ oriProps . onMouseDown ?.( e ) ;
227+ } ,
228+ onBlur : ( e : React . FocusEvent < HTMLDivElement > ) => {
229+ sharedProps . onBlur ( e ) ;
230+ oriProps . onBlur ?.( e ) ;
231+ } ,
232+ ref : rootRef ,
233+ } ) ;
234+ }
235+ return < RootComponent { ...sharedProps } ref = { rootRef } /> ;
236+ }
237+
215238 return (
216239 < SelectInputContext . Provider value = { contextValue } >
217240 < div
@@ -220,9 +243,8 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
220243 ref = { rootRef }
221244 className = { className }
222245 style = { style }
223- // Open
224- onMouseDown = { onInternalMouseDown }
225- onBlur = { onInternalBlur }
246+ // Shared Props
247+ { ...sharedProps }
226248 >
227249 { /* Prefix */ }
228250 < Affix className = { clsx ( `${ prefixCls } -prefix` , classNames ?. prefix ) } style = { styles ?. prefix } >
0 commit comments