@@ -29,53 +29,68 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
2929 return showSearch ? searchValue : '' ;
3030 } , [ combobox , activeValue , inputChanged , triggerOpen , searchValue , showSearch ] ) ;
3131
32- // Extract option props, excluding label and value, and handle className/style merging
33- const optionProps = React . useMemo ( ( ) => {
34- const restProps : React . HTMLAttributes < HTMLDivElement > = {
35- className : `${ prefixCls } -content-value` ,
36- style : mergedSearchValue
37- ? {
38- visibility : 'hidden' ,
39- }
40- : { } ,
41- } ;
32+ const [ optionClassName , optionStyle , optionTitle , hasOptionStyle ] = React . useMemo ( ( ) => {
33+ let className : string | undefined ;
34+ let style : React . CSSProperties | undefined ;
35+ let titleValue : string | undefined ;
4236
4337 if ( displayValue && selectContext ?. flattenOptions ) {
4438 const option = selectContext . flattenOptions . find ( ( opt ) => opt . value === displayValue . value ) ;
4539 if ( option ?. data ) {
46- const { className, style } = option . data ;
47- Object . assign ( restProps , {
48- title : getTitle ( option . data ) ,
49- className : clsx ( restProps . className , className ) ,
50- style : { ...restProps . style , ...style } ,
51- } ) ;
40+ className = option . data . className ;
41+ style = option . data . style ;
42+ titleValue = getTitle ( option . data ) ;
5243 }
5344 }
5445
55- if ( displayValue && ! restProps . title ) {
56- restProps . title = getTitle ( displayValue ) ;
46+ if ( displayValue && ! titleValue ) {
47+ titleValue = getTitle ( displayValue ) ;
5748 }
5849
5950 if ( rootTitle !== undefined ) {
60- restProps . title = rootTitle ;
51+ titleValue = rootTitle ;
6152 }
6253
63- return restProps ;
64- } , [ displayValue , selectContext ?. flattenOptions , prefixCls , mergedSearchValue , rootTitle ] ) ;
54+ const nextHasStyle = ! ! className || ! ! style ;
55+
56+ return [ className , style , titleValue , nextHasStyle ] as const ;
57+ } , [ displayValue , selectContext ?. flattenOptions , rootTitle ] ) ;
6558
6659 React . useEffect ( ( ) => {
6760 if ( combobox ) {
6861 setInputChanged ( false ) ;
6962 }
7063 } , [ combobox , activeValue ] ) ;
7164
65+ // ========================== Render ==========================
66+ // Render value
67+ const renderValue = displayValue ? (
68+ hasOptionStyle ? (
69+ < div
70+ className = { clsx ( `${ prefixCls } -content-value` , optionClassName ) }
71+ style = { {
72+ ...( mergedSearchValue ? { visibility : 'hidden' } : { } ) ,
73+ ...optionStyle ,
74+ } }
75+ title = { optionTitle }
76+ >
77+ { displayValue . label }
78+ </ div >
79+ ) : (
80+ displayValue . label
81+ )
82+ ) : (
83+ < Placeholder show = { ! mergedSearchValue } />
84+ ) ;
85+
86+ // Render
7287 return (
73- < div className = { clsx ( ` ${ prefixCls } -content` , classNames ?. content ) } style = { styles ?. content } >
74- { displayValue ? (
75- < div { ... optionProps } > { displayValue . label } </ div >
76- ) : (
77- < Placeholder show = { ! mergedSearchValue } / >
78- ) }
88+ < div
89+ className = { clsx ( ` ${ prefixCls } -content` , classNames ?. content ) }
90+ style = { styles ?. content }
91+ title = { hasOptionStyle ? undefined : optionTitle }
92+ >
93+ { renderValue }
7994 < Input
8095 ref = { ref }
8196 { ...inputProps }
0 commit comments