File tree Expand file tree Collapse file tree 3 files changed +36
-6
lines changed Expand file tree Collapse file tree 3 files changed +36
-6
lines changed Original file line number Diff line number Diff line change 1
1
# react-otp-input
2
+
2
3
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
+
3
5
[ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square )] ( #contributors- )
6
+
4
7
<!-- ALL-CONTRIBUTORS-BADGE:END -->
5
8
6
9
[ ![ npm version] ( https://badge.fury.io/js/react-otp-input.svg )] ( https://badge.fury.io/js/react-otp-input ) [ ![ npm] ( https://img.shields.io/npm/dw/react-otp-input.svg?logo=npm )] ( https://www.npmjs.com/package/react-otp-input )
@@ -78,6 +81,13 @@ export default class App extends Component {
78
81
<td>''</td>
79
82
<td>The value of the OTP passed into the component.</td>
80
83
</tr >
84
+ <tr>
85
+ <td>placeholder</td>
86
+ <td>string</td>
87
+ <td>false</td>
88
+ <td>none</td>
89
+ <td>Specify an expected value of each input. The length of this string should be equal to <code>numInputs</code>.</td>
90
+ </tr >
81
91
<tr >
82
92
<td>separator</td>
83
93
<td>component<br/></td>
@@ -201,6 +211,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
201
211
202
212
<!-- markdownlint-enable -->
203
213
<!-- prettier-ignore-end -->
214
+
204
215
<!-- ALL-CONTRIBUTORS-LIST:END -->
205
216
206
- This project follows the [ all-contributors] ( https://github.com/all-contributors/all-contributors ) specification. Contributions of any kind welcome!
217
+ This project follows the [ all-contributors] ( https://github.com/all-contributors/all-contributors ) specification. Contributions of any kind welcome!
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ class Demo extends Component {
17
17
isInputNum : false ,
18
18
minLength : 0 ,
19
19
maxLength : 40 ,
20
+ placeholder : '' ,
20
21
} ;
21
22
}
22
23
@@ -66,6 +67,7 @@ class Demo extends Component {
66
67
isInputNum,
67
68
minLength,
68
69
maxLength,
70
+ placeholder,
69
71
} = this . state ;
70
72
71
73
return (
@@ -119,6 +121,18 @@ class Demo extends Component {
119
121
/>
120
122
</ label >
121
123
</ div >
124
+ < div className = "side-bar__segment" >
125
+ < label htmlFor = "placeholder" >
126
+ placeholder
127
+ < input
128
+ id = "placeholder"
129
+ name = "placeholder"
130
+ type = "text"
131
+ value = { placeholder }
132
+ onChange = { this . handleChange }
133
+ />
134
+ </ label >
135
+ </ div >
122
136
< div className = "side-bar__segment" >
123
137
< label htmlFor = "disabled" >
124
138
< input
@@ -177,13 +191,14 @@ class Demo extends Component {
177
191
isInputNum = { isInputNum }
178
192
shouldAutoFocus
179
193
value = { otp }
194
+ placeholder = { placeholder }
180
195
/>
181
196
</ div >
182
197
< div className = "btn-row" >
183
198
< button
184
199
className = "btn margin-top--large"
185
200
type = "button"
186
- disabled = { isDisabled || otp . trim ( ) === "" }
201
+ disabled = { isDisabled || otp . trim ( ) === '' }
187
202
onClick = { this . clearOtp }
188
203
>
189
204
Clear
Original file line number Diff line number Diff line change @@ -145,12 +145,16 @@ class OtpInput extends Component<Props, State> {
145
145
146
146
getPlaceholderValue = ( ) => {
147
147
const { placeholder, numInputs } = this . props ;
148
+
148
149
if ( typeof placeholder === 'string' ) {
149
- if ( placeholder . length === 1 ) return placeholder . repeat ( numInputs ) ;
150
- else if ( placeholder . length === numInputs ) return placeholder ;
151
- else console . error ( 'Length of the placeholder should be either 1 or equal to the number of inputs' ) ;
150
+ if ( placeholder . length === numInputs ) {
151
+ return placeholder ;
152
+ }
153
+
154
+ if ( placeholder . length > 0 ) {
155
+ console . error ( 'Length of the placeholder should be equal to the number of inputs.' ) ;
156
+ }
152
157
}
153
- return ;
154
158
} ;
155
159
156
160
// Helper to return OTP from input
You can’t perform that action at this time.
0 commit comments