Skip to content

Commit 5669898

Browse files
committed
♻️ Demo: Update min/max numInputs length
1 parent 1d5dd39 commit 5669898

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/demo/index.jsx

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import React, { Component } from 'react';
22
import { render } from 'react-dom';
3+
34
import OtpInput from '../../lib';
45
import './styles.css';
56

67
class Demo extends Component {
78
constructor(props) {
89
super(props);
10+
911
this.state = {
1012
otp: '',
1113
numInputs: 4,
1214
separator: '-',
1315
isDisabled: false,
1416
hasErrored: false,
1517
isInputNum: false,
18+
minLength: 0,
19+
maxLength: 40,
1620
};
1721
}
1822

@@ -21,12 +25,17 @@ class Demo extends Component {
2125
};
2226

2327
handleChange = e => {
28+
const { minLength, maxLength } = this.state;
2429
let currVal = e.target.value;
25-
if(currVal<0) currVal = 0;
26-
if(currVal>10){
27-
currVal = 10;
28-
alert("No. of Inputs cannot be greater than 10");
30+
31+
if (currVal < minLength || currVal > maxLength) {
32+
currVal = 4;
33+
34+
console.error(
35+
`Please enter a value between ${minLength} and ${maxLength}`
36+
);
2937
}
38+
3039
this.setState({ [e.target.name]: currVal });
3140
};
3241

@@ -45,12 +54,24 @@ class Demo extends Component {
4554
};
4655

4756
render() {
48-
const { otp, numInputs, separator, isDisabled, hasErrored, isInputNum } = this.state;
57+
const {
58+
otp,
59+
numInputs,
60+
separator,
61+
isDisabled,
62+
hasErrored,
63+
isInputNum,
64+
minLength,
65+
maxLength,
66+
} = this.state;
4967

5068
return (
5169
<div className="container">
5270
<div className="side-bar">
53-
<a href="https://github.com/ajayns/react-otp-input" target="_blank">
71+
<a
72+
href="https://github.com/devfolioco/react-otp-input"
73+
target="_blank"
74+
>
5475
<div className="side-bar__segment side-bar__segment--header">
5576
<h2>react-otp-input</h2>
5677
</div>
@@ -64,8 +85,8 @@ class Demo extends Component {
6485
type="number"
6586
value={numInputs}
6687
onChange={this.handleChange}
67-
min="0"
68-
max="10"
88+
min={minLength}
89+
max={maxLength}
6990
/>
7091
</label>
7192
</div>
@@ -132,7 +153,7 @@ class Demo extends Component {
132153
</label>
133154
</div>
134155
<div className="side-bar__segment side-bar__segment--bottom">
135-
<a href="https://github.com/ajayns/react-otp-input">
156+
<a href="https://github.com/devfolioco/react-otp-input">
136157
Documentation and Source
137158
</a>
138159
</div>

0 commit comments

Comments
 (0)