File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -50,10 +50,10 @@ export default function useCursor(
50
50
51
51
let startPos = value . length ;
52
52
53
- if ( value . endsWith ( afterTxt ) ) {
54
- startPos = value . length - selectionRef . current . afterTxt . length ;
55
- } else if ( value . startsWith ( beforeTxt ) ) {
53
+ if ( value . startsWith ( beforeTxt ) ) {
56
54
startPos = beforeTxt . length ;
55
+ } else if ( value . endsWith ( afterTxt ) ) {
56
+ startPos = value . length - selectionRef . current . afterTxt . length ;
57
57
} else {
58
58
const beforeLastChar = beforeTxt [ start - 1 ] ;
59
59
const newIndex = value . indexOf ( beforeLastChar , start - 1 ) ;
Original file line number Diff line number Diff line change @@ -107,4 +107,14 @@ describe('InputNumber.Cursor', () => {
107
107
} ) ;
108
108
} ) ;
109
109
} ) ;
110
+
111
+ describe ( 'append string' , ( ) => {
112
+ it ( 'position caret before appended characters' , ( ) => {
113
+ const { container } = render ( < InputNumber formatter = { ( value ) => `${ value } %` } parser = { ( value ) => value . replace ( '%' , '' ) } /> ) ;
114
+ const input = container . querySelector ( 'input' ) ;
115
+ fireEvent . focus ( input ) ;
116
+ fireEvent . change ( input , { target : { value : '5' } } ) ;
117
+ expect ( cursorInput ( input ) ) . toEqual ( 1 ) ;
118
+ } ) ;
119
+ } ) ;
110
120
} ) ;
You can’t perform that action at this time.
0 commit comments