11import React , {
22 ChangeEvent ,
3- ClipboardEvent ,
43 createRef ,
54 InputHTMLAttributes ,
65 KeyboardEvent ,
@@ -139,6 +138,8 @@ const ReactInputVerificationCode = ({
139138
140139 const onInputChange = useCallback (
141140 ( event : ChangeEvent < HTMLInputElement > , index : number ) => {
141+ event . preventDefault ( ) ;
142+
142143 const eventValue = event . target . value ;
143144 console . log ( '-------' ) ;
144145 console . log ( 'RIVC:onInputChange' , {
@@ -149,9 +150,9 @@ const ReactInputVerificationCode = ({
149150 } ) ;
150151
151152 /**
152- * otp code
153+ * otp code or pasted value
153154 */
154- if ( eventValue . length > 2 ) {
155+ if ( eventValue . length > 1 ) {
155156 console . log ( 'RIVC: isOtp' , true ) ;
156157 console . log ( 'RIVC: fillValues(eventValue)' , fillValues ( eventValue ) ) ;
157158
@@ -166,6 +167,7 @@ const ReactInputVerificationCode = ({
166167 return ;
167168 }
168169
170+ focusInput ( eventValue . length ) ;
169171 return ;
170172 }
171173
@@ -243,32 +245,6 @@ const ReactInputVerificationCode = ({
243245 [ focusInput , focusedIndex , setValue , values ]
244246 ) ;
245247
246- const onInputPaste = useCallback (
247- ( event : ClipboardEvent < HTMLInputElement > , index : number ) => {
248- event . preventDefault ( ) ;
249-
250- const pastedValue = event . clipboardData . getData ( 'text' ) ;
251- const nextValues = pastedValue . slice ( 0 , length ) ;
252-
253- if ( ! validate ( nextValues ) ) {
254- return ;
255- }
256-
257- setValues ( fillValues ( nextValues ) ) ;
258-
259- const isCompleted = nextValues . length === length ;
260-
261- if ( isCompleted ) {
262- onCompleted ( nextValues ) ;
263- blurInput ( index ) ;
264- return ;
265- }
266-
267- focusInput ( nextValues . length ) ;
268- } ,
269- [ blurInput , fillValues , focusInput , length , onCompleted , validate ]
270- ) ;
271-
272248 /**
273249 * autoFocus
274250 */
@@ -282,14 +258,13 @@ const ReactInputVerificationCode = ({
282258 < div className = 'ReactInputVerificationCode-container' >
283259 { inputsRefs . map ( ( ref , i ) => (
284260 < input
285- autoComplete = { focusedIndex === i ? 'one-time-code' : 'off' }
261+ autoComplete = 'one-time-code'
286262 className = 'ReactInputVerificationCode-item'
287263 inputMode = { type === 'number' ? 'numeric' : 'text' }
288264 key = { i }
289265 onChange = { ( event ) => onInputChange ( event , i ) }
290266 onFocus = { ( ) => onInputFocus ( i ) }
291267 onKeyDown = { ( event ) => onInputKeyDown ( event , i ) }
292- onPaste = { ( event ) => onInputPaste ( event , i ) }
293268 placeholder = { placeholder }
294269 ref = { ref }
295270 value = { values [ i ] }
0 commit comments