@@ -105,37 +105,38 @@ export class CodeInputComponent implements AfterViewInit, OnInit, OnChanges {
105
105
e . preventDefault ( ) ;
106
106
e . stopPropagation ( ) ;
107
107
108
- const data = e . clipboardData ?. getData ( 'text' ) ;
108
+ const data = e . clipboardData ? e . clipboardData . getData ( 'text' ) : undefined ;
109
109
110
110
if ( this . isEmpty ( data ) ) {
111
111
return ;
112
112
}
113
113
114
114
// Convert paste text into iterable
115
115
const values = data . split ( '' ) ;
116
- let index = 0 ;
116
+ let valIndex = 0 ;
117
117
118
- for ( const val of values ) {
119
- const target = this . inputs [ i + index ] ;
120
-
121
- // Cancel the loop when a value cannot be used
122
- if ( ! this . canInputValue ( val ) ) {
123
- this . setInputValue ( target , null ) ;
124
- this . setStateForInput ( target , InputState . reset ) ;
125
- return ;
118
+ for ( let j = i ; j < this . inputs . length ; j ++ ) {
119
+ // The values end is reached. Loop exit
120
+ if ( valIndex === values . length ) {
121
+ break ;
126
122
}
127
123
128
- this . setInputValue ( target , val . toString ( ) ) ;
124
+ const input = this . inputs [ j ] ;
125
+ const val = values [ valIndex ] ;
129
126
130
- // Emit changes when we have reached the last input or we are at the last cycle of our values array
131
- if ( i + index + 1 > this . codeLength - 1 || index >= values . length - 1 ) {
132
- target . blur ( ) ;
133
- this . emitChanges ( ) ;
127
+ // Cancel the loop when a value cannot be used
128
+ if ( ! this . canInputValue ( val ) ) {
129
+ this . setInputValue ( input , null ) ;
130
+ this . setStateForInput ( input , InputState . reset ) ;
134
131
return ;
135
132
}
136
133
137
- index += 1 ;
134
+ this . setInputValue ( input , val . toString ( ) ) ;
135
+ valIndex ++ ;
138
136
}
137
+
138
+ this . inputs [ i ] . blur ( ) ;
139
+ this . emitChanges ( ) ;
139
140
}
140
141
141
142
async onKeydown ( e : any , i : number ) : Promise < void > {
0 commit comments