File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -224,9 +224,16 @@ class OtpInput extends Component<Props, State> {
224224 // Handle pasted OTP
225225 handleOnPaste = ( e : Object ) = > {
226226 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+
229235 const otp = this . getOtpValue ( ) ;
236+ let nextActiveInput = activeInput ;
230237
231238 // Get pastedData in an array of max size (num of inputs - current position)
232239 const pastedData = e . clipboardData
@@ -238,14 +245,14 @@ class OtpInput extends Component<Props, State> {
238245 for ( let pos = 0 ; pos < numInputs ; ++ pos ) {
239246 if ( pos >= activeInput && pastedData . length > 0 ) {
240247 otp [ pos ] = pastedData . shift ( ) ;
241- activeInput ++ ;
248+ nextActiveInput ++ ;
242249 }
243250 }
244251
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+ } ) ;
249256 } ;
250257
251258 handleOnChange = ( e : Object ) => {
You can’t perform that action at this time.
0 commit comments