Skip to content

Commit 1d1edd5

Browse files
committed
🐛 Input maxlength ignored with type="number"
1 parent 42bb59d commit 1d1edd5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-otp-input",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "A fully customizable, one-time password input component for the web built with React",
55
"main": "lib/index.js",
66
"scripts": {

src/lib/index.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ class OtpInput extends Component<Props, State> {
132132

133133
// Helper to return OTP from input
134134
getOtp = () => {
135-
this.props.onChange(this.state.otp.join(''));
135+
const { onChange, isInputNum } = this.props;
136+
const otp = this.state.otp.join('');
137+
onChange(isInputNum ? Number(otp) : otp);
136138
};
137139

138140
// Focus on input by index
@@ -160,7 +162,7 @@ class OtpInput extends Component<Props, State> {
160162
// Change OTP value at focused input
161163
changeCodeAtFocus = (value: string) => {
162164
const { activeInput, otp } = this.state;
163-
otp[activeInput] = value;
165+
otp[activeInput] = value[0];
164166

165167
this.setState({
166168
otp,

0 commit comments

Comments
 (0)