Skip to content

Commit e06ed10

Browse files
fix: Assign the pasted value from the clipboard auto paste to the otpValueRef to reflect on the input value
1 parent d3aa273 commit e06ed10

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef } from 'react';
1+
import React from 'react';
22

33
type 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

0 commit comments

Comments
 (0)