File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed
docs/.vuepress/components Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ export default {
7575 decimal: ' ,' ,
7676 separator: ' .' ,
7777 prefix: ' $' ,
78- suffix: ' ' ,
78+ suffix: ' % ' ,
7979 precision: 2 ,
8080 masked: false
8181 }
Original file line number Diff line number Diff line change @@ -115,6 +115,11 @@ export function inputHandler(event) {
115115 positionFromEnd = Math . max ( positionFromEnd , config . suffix . length )
116116 positionFromEnd = target . value . length - positionFromEnd
117117 positionFromEnd = Math . max ( positionFromEnd , config . prefix . length + 1 )
118+ const decimalPosition = target . value . indexOf ( config . decimal )
119+ if ( decimalPosition > 0 && ( positionFromEnd - decimalPosition ) <= config . precision ) {
120+ // eslint-disable-next-line no-plusplus
121+ positionFromEnd ++
122+ }
118123 updateCursor ( target , positionFromEnd )
119124
120125 if ( oldValue !== target . value ) {
Original file line number Diff line number Diff line change @@ -25,8 +25,14 @@ export default {
2525 handlerOwner . addEventListener ( 'input' , oninput , true )
2626
2727 el . onblur = ( e ) => core . blurHandler ( e )
28+ el . onclick = ( { target } ) => {
29+ const { selectionStart, value } = target
30+ if ( config . suffix . length && ( value . length - selectionStart ) < config . suffix . length ) core . updateCursor ( el , el . value . length - config . suffix . length )
31+ else if ( config . prefix . length && selectionStart < config . prefix . length ) core . updateCursor ( el , config . prefix . length )
32+ }
2833
2934 // check decimal key and insert to current element
35+ // updated cursor position after format the value
3036 el . onkeydown = ( e ) => {
3137 if ( e . key === '.' ) {
3238 e . preventDefault ( )
You can’t perform that action at this time.
0 commit comments