@@ -57,6 +57,11 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
5757 const formatValue =
5858 value === undefined || value === null ? '' : String ( value ) ;
5959
60+ // =================== Select Range ===================
61+ const [ selection , setSelection ] = React . useState <
62+ [ start : number , end : number ] | null
63+ > ( null ) ;
64+
6065 // ====================== Count =======================
6166 const countConfig = useCount ( count , showCount ) ;
6267 const mergedMax = countConfig . max || maxLength ;
@@ -104,6 +109,13 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
104109 cutValue = countConfig . exceedFormatter ( currentValue , {
105110 max : countConfig . max ,
106111 } ) ;
112+
113+ if ( currentValue !== cutValue ) {
114+ setSelection ( [
115+ inputRef . current ?. selectionStart || 0 ,
116+ inputRef . current ?. selectionEnd || 0 ,
117+ ] ) ;
118+ }
107119 }
108120 setValue ( cutValue ) ;
109121
@@ -112,6 +124,12 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
112124 }
113125 } ;
114126
127+ React . useEffect ( ( ) => {
128+ if ( selection ) {
129+ inputRef . current ?. setSelectionRange ( ...selection ) ;
130+ }
131+ } , [ selection ] ) ;
132+
115133 const onInternalChange : React . ChangeEventHandler < HTMLInputElement > = ( e ) => {
116134 triggerChange ( e , e . target . value ) ;
117135 } ;
0 commit comments