File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ export function inputHandler(event) {
133133 // updated cursor position
134134 positionFromEnd = Math . max ( positionFromEnd , config . suffix . length )
135135 positionFromEnd = target . value . length - positionFromEnd
136- positionFromEnd = Math . max ( positionFromEnd , config . prefix . length + 1 )
136+ positionFromEnd = Math . max ( positionFromEnd , config . prefix . length )
137137 updateCursor ( target , positionFromEnd )
138138
139139 if ( oldValue !== target . value ) {
Original file line number Diff line number Diff line change @@ -49,6 +49,24 @@ export default {
4949 el . value . includes ( config . decimal )
5050 ) {
5151 e . preventDefault ( )
52+ } else if ( [ 8 ] . includes ( e . keyCode ) ) {
53+ // check current cursor position is after separator when backspace key down
54+ const character = el . value . slice ( el . selectionEnd - 1 , el . selectionEnd )
55+ const replace = el . value . slice ( el . selectionEnd - 2 , el . selectionEnd )
56+ if ( character === config . separator ) {
57+ e . preventDefault ( )
58+
59+ let positionFromEnd = el . value . length - el . selectionEnd
60+ // remove separator and before character
61+ el . value = el . value . replace ( replace , '' )
62+ // updated cursor position
63+ positionFromEnd = Math . max ( positionFromEnd , config . suffix . length )
64+ positionFromEnd = el . value . length - positionFromEnd
65+ positionFromEnd = Math . max ( positionFromEnd , config . prefix . length )
66+ core . updateCursor ( el , positionFromEnd )
67+ // trigger input event
68+ el . dispatchEvent ( new Event ( 'input' ) )
69+ }
5270 }
5371 }
5472
You can’t perform that action at this time.
0 commit comments