Skip to content

Commit 6e404af

Browse files
realabbasnaveenvignesh5
authored andcommitted
add autoFocus prop
1 parent 5c68357 commit 6e404af

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The following props are applicable for the component along with **props supporte
3838
| containerStyle | object | Yes | {} | style for overall container. |
3939
| textInputStyle | object | Yes | {} | style for text input. |
4040
| testIDPrefix | string | Yes | 'otp*input*' | testID prefix, the result will be `otp_input_0` until inputCount |
41+
| autoFocus | bool | Yes | false | Input should automatically get focus when the components loads |
4142

4243
#### Helper Functions
4344

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class OTPTextView extends Component {
223223
key={i}
224224
autoCorrect={false}
225225
keyboardType={keyboardType}
226-
autoFocus={i === 0}
226+
autoFocus={this.props.autoFocus && i === 0}
227227
value={otpText[i] || ""}
228228
style={inputStyle}
229229
maxLength={this.props.inputCellLength}
@@ -260,6 +260,7 @@ OTPTextView.propTypes = {
260260
inputType: PropTypes.string,
261261
keyboardType: PropTypes.string,
262262
testIDPrefix: PropTypes.string,
263+
autoFocus: PropTypes.bool
263264
};
264265

265266
OTPTextView.defaultProps = {
@@ -273,6 +274,7 @@ OTPTextView.defaultProps = {
273274
handleTextChange: () => {},
274275
keyboardType: "numeric",
275276
testIDPrefix: "otp_input_",
277+
autoFocus: false
276278
};
277279

278280
export default OTPTextView;

0 commit comments

Comments
 (0)