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 11# react-otp-input
2+
23<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4+
35[ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square )] ( #contributors- )
6+
47<!-- ALL-CONTRIBUTORS-BADGE:END -->
58
69[ ![ 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 {
7881 <td>''</td>
7982 <td>The value of the OTP passed into the component.</td>
8083 </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 >
8191 <tr >
8292 <td>separator</td>
8393 <td>component<br/></td>
@@ -201,6 +211,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
201211
202212<!-- markdownlint-enable -->
203213<!-- prettier-ignore-end -->
214+
204215<!-- ALL-CONTRIBUTORS-LIST:END -->
205216
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 {
1717 isInputNum : false ,
1818 minLength : 0 ,
1919 maxLength : 40 ,
20+ placeholder : '' ,
2021 } ;
2122 }
2223
@@ -66,6 +67,7 @@ class Demo extends Component {
6667 isInputNum,
6768 minLength,
6869 maxLength,
70+ placeholder,
6971 } = this . state ;
7072
7173 return (
@@ -119,6 +121,18 @@ class Demo extends Component {
119121 />
120122 </ label >
121123 </ 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 >
122136 < div className = "side-bar__segment" >
123137 < label htmlFor = "disabled" >
124138 < input
@@ -177,13 +191,14 @@ class Demo extends Component {
177191 isInputNum = { isInputNum }
178192 shouldAutoFocus
179193 value = { otp }
194+ placeholder = { placeholder }
180195 />
181196 </ div >
182197 < div className = "btn-row" >
183198 < button
184199 className = "btn margin-top--large"
185200 type = "button"
186- disabled = { isDisabled || otp . trim ( ) === "" }
201+ disabled = { isDisabled || otp . trim ( ) === '' }
187202 onClick = { this . clearOtp }
188203 >
189204 Clear
Original file line number Diff line number Diff line change @@ -145,12 +145,16 @@ class OtpInput extends Component<Props, State> {
145145
146146 getPlaceholderValue = ( ) => {
147147 const { placeholder, numInputs } = this . props ;
148+
148149 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+ }
152157 }
153- return ;
154158 } ;
155159
156160 // Helper to return OTP from input
You can’t perform that action at this time.
0 commit comments