File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import React , { useRef } from 'react' ;
1+ import React from 'react' ;
22
33type AllowedInputTypes = 'password' | 'text' | 'number' | 'tel' ;
44
@@ -124,11 +124,13 @@ const OTPInput = ({
124124 // Pasting from the native autofill suggestion on a mobile device can pass
125125 // the pasted string as one long input to one of the cells. This ensures
126126 // that we handle the full input and not just the first character.
127- if ( value . length === numInputs ) {
128- const hasInvalidInput = value . split ( '' ) . some ( ( cellInput ) => ! isInputValueValid ( cellInput ) ) ;
127+ if ( value . length >= numInputs ) {
128+ const valueArr = value . split ( '' , numInputs ) ;
129+ const hasInvalidInput = valueArr . some ( ( cellInput ) => ! isInputValueValid ( cellInput ) ) ;
129130 if ( ! hasInvalidInput ) {
130- handleOTPChange ( value . split ( '' ) ) ;
131+ handleOTPChange ( valueArr ) ;
131132 focusInput ( numInputs - 1 ) ;
133+ otpValueRef . current = valueArr ;
132134 }
133135 }
134136
You can’t perform that action at this time.
0 commit comments