@@ -34,10 +34,30 @@ export default {
3434 if ( ( [ 110 , 190 ] . includes ( e . keyCode ) || e . key === config . decimal ) && ! el . value . includes ( config . decimal ) ) {
3535 e . preventDefault ( )
3636 el . setRangeText ( config . decimal )
37- core . updateValue ( el , null , { emit : true } , e )
37+ core . updateValue ( el , null , { emit : true } )
3838 core . updateCursor ( el , el . value . indexOf ( config . decimal ) + 1 )
39- } else if ( ( [ 110 , 190 ] . includes ( e . keyCode ) || e . key === config . decimal ) && el . value . includes ( config . decimal ) ) {
39+ } else if (
40+ ( [ 110 , 190 ] . includes ( e . keyCode ) || e . key === config . decimal ) && el . value . includes ( config . decimal )
41+ ) {
4042 e . preventDefault ( )
43+ } else if ( [ 8 ] . includes ( e . keyCode ) ) {
44+ // check current cursor position is after separator when backspace key down
45+ const character = el . value . slice ( el . selectionEnd - 1 , el . selectionEnd )
46+ const replace = el . value . slice ( el . selectionEnd - 2 , el . selectionEnd )
47+ if ( character === config . separator ) {
48+ e . preventDefault ( )
49+
50+ let positionFromEnd = el . value . length - el . selectionEnd
51+ // remove separator and before character
52+ el . value = el . value . replace ( replace , '' )
53+ // updated cursor position
54+ positionFromEnd = Math . max ( positionFromEnd , config . suffix . length )
55+ positionFromEnd = el . value . length - positionFromEnd
56+ positionFromEnd = Math . max ( positionFromEnd , config . prefix . length )
57+ core . updateCursor ( el , positionFromEnd )
58+ // trigger input event
59+ el . dispatchEvent ( new Event ( 'input' ) )
60+ }
4161 }
4262 }
4363
0 commit comments