diff --git a/README.md b/README.md
index 4536338..a49d938 100644
--- a/README.md
+++ b/README.md
@@ -140,7 +140,9 @@ Do not override the following props on the input component that you return from
- `onBlur`
- `onKeyDown`
- `onPaste`
+- `onInput`
- `type`
+- `inputMode`
## Migrating from v2
diff --git a/example/src/App.tsx b/example/src/App.tsx
index 9fd11d7..b08cce1 100644
--- a/example/src/App.tsx
+++ b/example/src/App.tsx
@@ -95,6 +95,7 @@ function App() {
+
diff --git a/package.json b/package.json
index 3dfbae5..73635e1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "react-otp-input",
- "version": "3.0.2",
+ "version": "3.0.3",
"description": "A fully customizable, one-time password input component for the web built with React",
"main": "lib/index.js",
"module": "lib/index.esm.js",
diff --git a/src/index.tsx b/src/index.tsx
index de05ad6..ca66b17 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -15,6 +15,8 @@ type InputProps = Required<
| 'maxLength'
| 'autoComplete'
| 'style'
+ | 'inputMode'
+ | 'onInput'
> & {
ref: React.RefCallback;
placeholder: string | undefined;
@@ -101,8 +103,12 @@ const OTPInput = ({
if (isInputValueValid(value)) {
changeCodeAtFocus(value);
focusInput(activeInput + 1);
- } else {
- const { nativeEvent } = event;
+ }
+ };
+
+ const handleInputChange = (event: React.ChangeEvent) => {
+ const { nativeEvent } = event;
+ if (!isInputValueValid(event.target.value)) {
// @ts-expect-error - This was added previosly to handle and edge case
// for dealing with keyCode "229 Unidentified" on Android. Check if this is
// still needed.
@@ -111,6 +117,9 @@ const OTPInput = ({
changeCodeAtFocus('');
focusInput(activeInput - 1);
}
+ // Clear the input if it's not valid value because firefox allows
+ // pasting non-numeric characters in a number type input
+ event.target.value = '';
}
};
@@ -151,8 +160,6 @@ const OTPInput = ({
event.code === 'ArrowDown'
) {
event.preventDefault();
- } else if (isInputNum && !isInputValueValid(event.key)) {
- event.preventDefault();
}
};
@@ -232,6 +239,8 @@ const OTPInput = ({
),
className: typeof inputStyle === 'string' ? inputStyle : undefined,
type: inputType,
+ inputMode: isInputNum ? 'numeric' : 'text',
+ onInput: handleInputChange,
},
index
)}