@@ -12,7 +12,6 @@ type InputProps = Required<
12
12
| 'onKeyDown'
13
13
| 'onPaste'
14
14
| 'aria-label'
15
- | 'maxLength'
16
15
| 'autoComplete'
17
16
| 'style'
18
17
| 'inputMode'
@@ -114,15 +113,29 @@ const OTPInput = ({
114
113
115
114
const handleInputChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
116
115
const { nativeEvent } = event ;
117
- if ( ! isInputValueValid ( event . target . value ) ) {
118
- // @ts -expect-error - This was added previosly to handle and edge case
116
+ const value = event . target . value ;
117
+
118
+ if ( ! isInputValueValid ( value ) ) {
119
+ // Pasting from the native autofill suggestion on a mobile device can pass
120
+ // the pasted string as one long input to one of the cells. This ensures
121
+ // that we handle the full input and not just the first character.
122
+ if ( value . length === numInputs ) {
123
+ const hasInvalidInput = value . split ( '' ) . some ( ( cellInput ) => ! isInputValueValid ( cellInput ) ) ;
124
+ if ( ! hasInvalidInput ) {
125
+ handleOTPChange ( value . split ( '' ) ) ;
126
+ focusInput ( numInputs - 1 ) ;
127
+ }
128
+ }
129
+
130
+ // @ts -expect-error - This was added previously to handle and edge case
119
131
// for dealing with keyCode "229 Unidentified" on Android. Check if this is
120
132
// still needed.
121
133
if ( nativeEvent . data === null && nativeEvent . inputType === 'deleteContentBackward' ) {
122
134
event . preventDefault ( ) ;
123
135
changeCodeAtFocus ( '' ) ;
124
136
focusInput ( activeInput - 1 ) ;
125
137
}
138
+
126
139
// Clear the input if it's not valid value because firefox allows
127
140
// pasting non-numeric characters in a number type input
128
141
event . target . value = '' ;
@@ -238,7 +251,6 @@ const OTPInput = ({
238
251
onKeyDown : handleKeyDown ,
239
252
onPaste : handlePaste ,
240
253
autoComplete : 'off' ,
241
- maxLength : 1 ,
242
254
'aria-label' : `Please enter OTP character ${ index + 1 } ` ,
243
255
style : Object . assign (
244
256
! skipDefaultStyles ? ( { width : '1em' , textAlign : 'center' } as const ) : { } ,
0 commit comments