@@ -34,7 +34,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
3434 autoComplete,
3535 ...restProps
3636 } = props ;
37- const { prefixCls, mode, onSearch, onSearchSubmit, onInputBlur, autoFocus } =
37+ const { prefixCls, mode, onSearch, onSearchSubmit, onInputBlur, autoFocus, tokenWithEnter } =
3838 useSelectInputContext ( ) ;
3939 const { id, classNames, styles, open, activeDescendantId, role, disabled } = useBaseProps ( ) || { } ;
4040
@@ -43,6 +43,9 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
4343 // Used to handle input method composition status
4444 const compositionStatusRef = React . useRef < boolean > ( false ) ;
4545
46+ // Used to handle paste content, similar to original Selector implementation
47+ const pastedTextRef = React . useRef < string | null > ( null ) ;
48+
4649 // ============================== Refs ==============================
4750 const inputRef = React . useRef < HTMLInputElement > ( null ) ;
4851
@@ -51,7 +54,20 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
5154 // ============================== Data ==============================
5255 // Handle input changes
5356 const handleChange : React . ChangeEventHandler < HTMLInputElement > = ( event ) => {
54- const { value : nextVal } = event . target ;
57+ let { value : nextVal } = event . target ;
58+
59+ // Handle pasted text with tokenWithEnter, similar to original Selector implementation
60+ if ( tokenWithEnter && pastedTextRef . current && / [ \r \n ] / . test ( pastedTextRef . current ) ) {
61+ // CRLF will be treated as a single space for input element
62+ const replacedText = pastedTextRef . current
63+ . replace ( / [ \r \n ] + $ / , '' )
64+ . replace ( / \r \n / g, ' ' )
65+ . replace ( / [ \r \n ] / g, ' ' ) ;
66+ nextVal = nextVal . replace ( replacedText , pastedTextRef . current ) ;
67+ }
68+
69+ // Reset pasted text reference
70+ pastedTextRef . current = null ;
5571
5672 // Call onSearch callback
5773 if ( onSearch ) {
@@ -95,9 +111,18 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
95111 const handleCompositionEnd : React . CompositionEventHandler < HTMLInputElement > = ( event ) => {
96112 compositionStatusRef . current = false ;
97113
98- // Trigger search when input method composition ends
99- const { value : nextVal } = event . currentTarget ;
100- onSearch ?.( nextVal , true , false ) ;
114+ // Trigger search when input method composition ends, similar to original Selector
115+ if ( mode !== 'combobox' ) {
116+ const { value : nextVal } = event . currentTarget ;
117+ onSearch ?.( nextVal , true , false ) ;
118+ }
119+ } ;
120+
121+ // Handle paste events to track pasted content
122+ const handlePaste : React . ClipboardEventHandler < HTMLInputElement > = ( event ) => {
123+ const { clipboardData } = event ;
124+ const pastedValue = clipboardData ?. getData ( 'text' ) ;
125+ pastedTextRef . current = pastedValue || '' ;
101126 } ;
102127
103128 // ============================= Width ==============================
@@ -139,6 +164,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
139164 onChange = { handleChange }
140165 onKeyDown = { handleKeyDown }
141166 onBlur = { handleBlur }
167+ onPaste = { handlePaste }
142168 onCompositionStart = { handleCompositionStart }
143169 onCompositionEnd = { handleCompositionEnd }
144170 // Accessibility attributes
0 commit comments