Skip to content

Commit 4b2f3bc

Browse files
committed
✨ Add isInputNum prop to lib
1 parent 70850c1 commit 4b2f3bc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib/index.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Props = {
1919
hasErrored?: boolean,
2020
errorStyle?: Object,
2121
shouldAutoFocus?: boolean,
22+
isInputNum?: boolean,
2223
};
2324

2425
type State = {
@@ -76,9 +77,12 @@ class SingleOtpInput extends PureComponent<*> {
7677
focusStyle,
7778
disabledStyle,
7879
shouldAutoFocus,
80+
isInputNum,
7981
...rest
8082
} = this.props;
8183

84+
const numValueLimits = isInputNum ? { min: 0, max: 9 } : {};
85+
8286
return (
8387
<div style={{ display: 'flex', alignItems: 'center' }}>
8488
<input
@@ -94,7 +98,8 @@ class SingleOtpInput extends PureComponent<*> {
9498
isDisabled && disabledStyle,
9599
hasErrored && errorStyle
96100
)}
97-
type="tel"
101+
type={isInputNum ? 'number' : 'tel'}
102+
{...numValueLimits}
98103
maxLength="1"
99104
ref={input => {
100105
this.input = input;
@@ -227,6 +232,7 @@ class OtpInput extends Component<Props, State> {
227232
hasErrored,
228233
errorStyle,
229234
shouldAutoFocus,
235+
isInputNum,
230236
} = this.props;
231237
const inputs = [];
232238

@@ -255,6 +261,7 @@ class OtpInput extends Component<Props, State> {
255261
hasErrored={hasErrored}
256262
errorStyle={errorStyle}
257263
shouldAutoFocus={shouldAutoFocus}
264+
isInputNum={isInputNum}
258265
/>
259266
);
260267
}

0 commit comments

Comments
 (0)