File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -224,9 +224,16 @@ class OtpInput extends Component<Props, State> {
224
224
// Handle pasted OTP
225
225
handleOnPaste = ( e : Object ) = > {
226
226
e . preventDefault ( ) ;
227
- const { numInputs } = this . props ;
228
- var { activeInput } = this . state ;
227
+
228
+ const { activeInput } = this . state ;
229
+ const { numInputs , isDisabled } = this . props ;
230
+
231
+ if ( isDisabled ) {
232
+ return ;
233
+ }
234
+
229
235
const otp = this . getOtpValue ( ) ;
236
+ let nextActiveInput = activeInput ;
230
237
231
238
// Get pastedData in an array of max size (num of inputs - current position)
232
239
const pastedData = e . clipboardData
@@ -238,14 +245,14 @@ class OtpInput extends Component<Props, State> {
238
245
for ( let pos = 0 ; pos < numInputs ; ++ pos ) {
239
246
if ( pos >= activeInput && pastedData . length > 0 ) {
240
247
otp [ pos ] = pastedData . shift ( ) ;
241
- activeInput ++ ;
248
+ nextActiveInput ++ ;
242
249
}
243
250
}
244
251
245
- this . setState ( { activeInput } ) ;
246
- this . focusInput ( activeInput ) ;
247
-
248
- this . handleOtpChange ( otp ) ;
252
+ this . setState ( { activeInput : nextActiveInput } , ( ) => {
253
+ this . focusInput ( activeInput ) ;
254
+ this . handleOtpChange ( otp ) ;
255
+ } ) ;
249
256
} ;
250
257
251
258
handleOnChange = ( e : Object ) => {
You can’t perform that action at this time.
0 commit comments