Skip to content

Commit

Permalink
Merge pull request #33 from EddWills95/allow-autocomplete-prop
Browse files Browse the repository at this point in the history
feat: add `autoComplete` to `TextInput`
  • Loading branch information
anday013 authored Jan 8, 2024
2 parents f8e7dbb + d519da2 commit a156eb9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ The `react-native-otp-entry` component accepts the following props:
| `onFilled` | (text: string) => void | A callback function is invoked when the OTP input is fully filled. It receives a full otp code as an argument. |
| `hideStick` | boolean | Hide cursor of the focused input. |
| `theme` | Theme | Custom styles for each element. |
| `focusStickBlinkingDuration` | number | The duration (in milliseconds) for the focus stick to blink. |
| `focusStickBlinkingDuration` | number | The duration (in milliseconds) for the focus stick to blink.
| `autoComplete` | string | passed to underlying TextInput (see: https://reactnative.dev/docs/textinput#autocomplete) |

| Theme | Type | Description |
| ------------------------------ | --------- | ---------------------------------------------------------------------------------- |
Expand Down
4 changes: 2 additions & 2 deletions dist/src/OtpInput/OtpInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const VerticalStick_1 = require("./VerticalStick");
const useOtpInput_1 = require("./useOtpInput");
exports.OtpInput = (0, react_1.forwardRef)((props, ref) => {
const { models: { text, inputRef, focusedInputIndex }, actions: { clear, handlePress, handleTextChange, focus }, forms: { setTextWithRef }, } = (0, useOtpInput_1.useOtpInput)(props);
const { numberOfDigits, autoFocus = true, hideStick, focusColor = "#A4D0A4", focusStickBlinkingDuration, secureTextEntry = false, theme = {}, } = props;
const { numberOfDigits, autoFocus = true, hideStick, focusColor = "#A4D0A4", focusStickBlinkingDuration, secureTextEntry = false, autoComplete = "sms-otp", theme = {}, } = props;
const { containerStyle, inputsContainerStyle, pinCodeContainerStyle, pinCodeTextStyle, focusStickStyle, focusedPinCodeContainerStyle, } = theme;
(0, react_1.useImperativeHandle)(ref, () => ({ clear, focus, setValue: setTextWithRef }));
return (<react_native_1.View style={[OtpInput_styles_1.styles.container, containerStyle]}>
Expand All @@ -32,6 +32,6 @@ exports.OtpInput = (0, react_1.forwardRef)((props, ref) => {
</react_native_1.Pressable>);
})}
</react_native_1.View>
<react_native_1.TextInput value={text} onChangeText={handleTextChange} maxLength={numberOfDigits} inputMode="numeric" textContentType="oneTimeCode" ref={inputRef} autoFocus={autoFocus} style={OtpInput_styles_1.styles.hiddenInput} secureTextEntry={secureTextEntry} testID="otp-input-hidden"/>
<react_native_1.TextInput value={text} onChangeText={handleTextChange} maxLength={numberOfDigits} inputMode="numeric" textContentType="oneTimeCode" ref={inputRef} autoFocus={autoFocus} style={OtpInput_styles_1.styles.hiddenInput} secureTextEntry={secureTextEntry} autoComplete={autoComplete} testID="otp-input-hidden"/>
</react_native_1.View>);
});
3 changes: 2 additions & 1 deletion dist/src/OtpInput/OtpInput.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorValue, TextStyle, ViewStyle } from "react-native";
import { ColorValue, TextInputProps, TextStyle, ViewStyle } from "react-native";
export interface OtpInputProps {
numberOfDigits: number;
autoFocus?: boolean;
Expand All @@ -9,6 +9,7 @@ export interface OtpInputProps {
focusStickBlinkingDuration?: number;
secureTextEntry?: boolean;
theme?: Theme;
autoComplete?: TextInputProps["autoComplete"];
}
export interface OtpInputRef {
clear: () => void;
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"jest": "^29.7.0",
"prettier": "^3.0.2",
"react": "18.2.0",
"react-native": "0.71.8",
"react-native": "0.71.9",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
Expand Down
1 change: 1 addition & 0 deletions src/OtpInput/OtpInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
autoFocus={autoFocus}
style={styles.hiddenInput}
secureTextEntry={secureTextEntry}
autoComplete="one-time-code"
testID="otp-input-hidden"
/>
</View>
Expand Down
1 change: 1 addition & 0 deletions src/OtpInput/__snapshots__/OtpInput.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ exports[`OtpInput UI should render correctly 1`] = `
</View>
</View>
<TextInput
autoComplete="one-time-code"
autoFocus={true}
inputMode="numeric"
maxLength={6}
Expand Down

0 comments on commit a156eb9

Please sign in to comment.