@@ -226,6 +226,7 @@ export default class MaskUtils {
226226 { value, selection } ,
227227 { value : previousValue , selection : previousSelection }
228228 ) => {
229+ const { maskPlaceholder } = this . maskOptions ;
229230 if (
230231 // Autocomplete will set the previous selection to the length of the autocompleted value
231232 previousSelection . end < previousValue . length &&
@@ -243,9 +244,26 @@ export default class MaskUtils {
243244 // When both previous and current state have no selection length, the cursor index is less than it was before
244245 // and the cursor is at the end of the new value
245246 // Check each character to see if there are any changes which is only possible if the value was autocompleted.
246- return value
247- . split ( "" )
248- . some ( ( char , index ) => char !== previousValue [ index ] ) ;
247+ return value . split ( "" ) . some ( ( char , index ) => {
248+ return char !== previousValue [ index ] ;
249+ } ) ;
250+ }
251+
252+ if (
253+ ! maskPlaceholder &&
254+ previousSelection . length === 0 &&
255+ previousValue . length < value . length
256+ ) {
257+ // If there is no mask placeholder, the selection is 0 and the new value is longer than the previous value
258+ // (characters have been added)
259+ return value . split ( "" ) . some ( ( char , index ) => {
260+ // Check each character before the selection to see if they have changed
261+ if ( index < previousSelection . start ) {
262+ // Any character before the previous selection that changes will be changed because of autofill
263+ return char !== previousValue [ index ] ;
264+ }
265+ return false ;
266+ } ) ;
249267 }
250268
251269 return false ;
@@ -264,8 +282,12 @@ export default class MaskUtils {
264282
265283 if ( this . isAutoFilled ( currentState , previousState ) ) {
266284 // If the value is autocompleted treat it as if the input started empty.
267- previousValue = "" ;
268- previousSelection = { start : 0 , end : 0 , length : 0 } ;
285+ previousValue = prefix ;
286+ previousSelection = {
287+ start : 0 ,
288+ end : 0 ,
289+ length : 0
290+ } ;
269291 }
270292
271293 if ( selection . end > previousSelection . start ) {
0 commit comments