11import * as React from 'react' ;
2+ import clsx from 'clsx' ;
23import Input from '../Input' ;
34import { useSelectInputContext } from '../context' ;
45import useBaseProps from '../../hooks/useBaseProps' ;
56import Placeholder from './Placeholder' ;
67import type { SharedContentProps } from '.' ;
8+ import SelectContext from '../../SelectContext' ;
79
810export default React . forwardRef < HTMLInputElement , SharedContentProps > ( function SingleContent (
911 { inputProps } ,
@@ -12,6 +14,7 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function S
1214 const { prefixCls, searchValue, activeValue, displayValues, maxLength, mode } =
1315 useSelectInputContext ( ) ;
1416 const { triggerOpen } = useBaseProps ( ) ;
17+ const selectContext = React . useContext ( SelectContext ) ;
1518
1619 const [ inputChanged , setInputChanged ] = React . useState ( false ) ;
1720
@@ -24,6 +27,32 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function S
2427 mergedSearchValue = activeValue ;
2528 }
2629
30+ // Extract option props, excluding label and value, and handle className/style merging
31+ const optionProps = React . useMemo ( ( ) => {
32+ let restProps = {
33+ className : `${ prefixCls } -content-value` ,
34+ style : {
35+ visibility : mergedSearchValue ? 'hidden' : 'visible' ,
36+ } ,
37+ } ;
38+
39+ if ( displayValue && selectContext ?. flattenOptions ) {
40+ const option = selectContext . flattenOptions . find ( ( opt ) => opt . value === displayValue . value ) ;
41+ if ( option ?. data ) {
42+ const { label, value, className, style, ...rest } = option . data ;
43+
44+ restProps = {
45+ ...restProps ,
46+ ...rest ,
47+ className : clsx ( restProps . className , className ) ,
48+ style : { ...restProps . style , ...style } ,
49+ } ;
50+ }
51+ }
52+
53+ return restProps ;
54+ } , [ displayValue , selectContext ?. flattenOptions , prefixCls , mergedSearchValue ] ) ;
55+
2756 React . useEffect ( ( ) => {
2857 if ( combobox ) {
2958 setInputChanged ( false ) ;
@@ -33,14 +62,7 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function S
3362 return (
3463 < div className = { `${ prefixCls } -content` } >
3564 { displayValue ? (
36- < div
37- className = { `${ prefixCls } -content-value` }
38- style = { {
39- visibility : mergedSearchValue ? 'hidden' : 'visible' ,
40- } }
41- >
42- { displayValue . label }
43- </ div >
65+ < div { ...optionProps } > { displayValue . label } </ div >
4466 ) : (
4567 < Placeholder hasSearchValue = { ! ! mergedSearchValue } />
4668 ) }
0 commit comments