Skip to content

Commit 94e5c67

Browse files
aromalanilapollonian
authored andcommitted
Added Check for string type
1 parent 88b462a commit 94e5c67

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/lib/index.jsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Props = {
2323
shouldAutoFocus?: boolean,
2424
isInputNum?: boolean,
2525
value?: string,
26-
className?: string
26+
className?: string,
2727
};
2828

2929
type State = {
@@ -138,21 +138,22 @@ class OtpInput extends Component<Props, State> {
138138
getOtpValue = () =>
139139
this.props.value ? this.props.value.toString().split('') : [];
140140

141-
getPlaceholderValue=()=>{
142-
const {placeholder,numInputs}= this.props;
141+
getPlaceholderValue = () => {
142+
const { placeholder, numInputs } = this.props;
143143

144-
if(!placeholder) return;
145-
146-
if(placeholder.length===1){
144+
if (typeof placeholder !== 'string'){
145+
console.error("Placeholder should be a string");
146+
return;
147+
}
148+
149+
if (placeholder.length === 1) {
147150
return placeholder.repeat(numInputs);
151+
} else if (placeholder.length === numInputs) {
152+
return placeholder;
153+
} else {
154+
console.error('Invalid placeholder value');
148155
}
149-
else if(placeholder.length===numInputs){
150-
return placeholder
151-
}
152-
else{
153-
console.error("Invalid placeholder value");
154-
}
155-
}
156+
};
156157

157158
// Helper to return OTP from input
158159
handleOtpChange = (otp: string[]) => {

0 commit comments

Comments
 (0)