Skip to content

Commit 9cdba96

Browse files
aromalanilapollonian
authored andcommitted
fix : Error message shown when placeholder is not passed
1 parent 94e5c67 commit 9cdba96

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/lib/index.jsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ class SingleOtpInput extends PureComponent<*> {
9090
} = this.props;
9191

9292
return (
93-
<div className={className} style={{ display: 'flex', alignItems: 'center' }}>
93+
<div
94+
className={className}
95+
style={{ display: 'flex', alignItems: 'center' }}
96+
>
9497
<input
9598
autoComplete="off"
9699
style={Object.assign(
@@ -140,18 +143,19 @@ class OtpInput extends Component<Props, State> {
140143

141144
getPlaceholderValue = () => {
142145
const { placeholder, numInputs } = this.props;
146+
if (placeholder !== undefined) {
147+
if (typeof placeholder !== 'string') {
148+
console.error('Placeholder should be a string');
149+
return;
150+
}
143151

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

@@ -291,7 +295,7 @@ class OtpInput extends Component<Props, State> {
291295
errorStyle,
292296
shouldAutoFocus,
293297
isInputNum,
294-
className
298+
className,
295299
} = this.props;
296300
const otp = this.getOtpValue();
297301
const inputs = [];

0 commit comments

Comments
 (0)