@@ -15,6 +15,8 @@ type InputProps = Required<
15
15
| 'maxLength'
16
16
| 'autoComplete'
17
17
| 'style'
18
+ | 'inputMode'
19
+ | 'onInput'
18
20
> & {
19
21
ref : React . RefCallback < HTMLInputElement > ;
20
22
placeholder : string | undefined ;
@@ -101,8 +103,12 @@ const OTPInput = ({
101
103
if ( isInputValueValid ( value ) ) {
102
104
changeCodeAtFocus ( value ) ;
103
105
focusInput ( activeInput + 1 ) ;
104
- } else {
105
- const { nativeEvent } = event ;
106
+ }
107
+ } ;
108
+
109
+ const handleInputChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
110
+ const { nativeEvent } = event ;
111
+ if ( ! isInputValueValid ( event . target . value ) ) {
106
112
// @ts -expect-error - This was added previosly to handle and edge case
107
113
// for dealing with keyCode "229 Unidentified" on Android. Check if this is
108
114
// still needed.
@@ -111,6 +117,9 @@ const OTPInput = ({
111
117
changeCodeAtFocus ( '' ) ;
112
118
focusInput ( activeInput - 1 ) ;
113
119
}
120
+ // Clear the input if it's not valid value because firefox allows
121
+ // pasting non-numeric characters in a number type input
122
+ event . target . value = '' ;
114
123
}
115
124
} ;
116
125
@@ -151,8 +160,6 @@ const OTPInput = ({
151
160
event . code === 'ArrowDown'
152
161
) {
153
162
event . preventDefault ( ) ;
154
- } else if ( isInputNum && ! isInputValueValid ( event . key ) ) {
155
- event . preventDefault ( ) ;
156
163
}
157
164
} ;
158
165
@@ -232,6 +239,8 @@ const OTPInput = ({
232
239
) ,
233
240
className : typeof inputStyle === 'string' ? inputStyle : undefined ,
234
241
type : inputType ,
242
+ inputMode : isInputNum ? 'numeric' : 'text' ,
243
+ onInput : handleInputChange ,
235
244
} ,
236
245
index
237
246
) }
0 commit comments