Skip to content

Commit a995c80

Browse files
feat: add testIDs for android with automation supports
1 parent 6801a6d commit a995c80

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/OtpInput/OtpInput.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
2323
theme = {},
2424
textInputProps,
2525
textProps,
26+
buttonProps,
2627
type = "numeric",
2728
} = props;
2829
const {
@@ -82,7 +83,9 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
8283
disabled={disabled}
8384
onPress={handlePress}
8485
style={generatePinCodeContainerStyle(isFocusedContainer, char)}
85-
testID="otp-input"
86+
{...buttonProps}
87+
testID={buttonProps?.testID ? `${buttonProps.testID}-${index}` : `otp-input-${index}`}
88+
{...Platform.OS === 'android' && { accessibilityLabel: buttonProps?.testID ? `${buttonProps.testID}-${index}` : `otp-input-${index}` }}
8689
>
8790
{isFocusedInput && !hideStick ? (
8891
<VerticalStick
@@ -94,6 +97,7 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
9497
<Text
9598
{...textProps}
9699
testID={textProps?.testID ? `${textProps.testID}-${index}` : undefined}
100+
{...Platform.OS === 'android' && { accessibilityLabel: textProps?.testID ? `${textProps.testID}-${index}` : `otp-input-text-${index}` }}
97101
style={[
98102
styles.codeText,
99103
pinCodeTextStyle,
@@ -120,6 +124,7 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
120124
aria-disabled={disabled}
121125
editable={!disabled}
122126
testID="otp-input-hidden"
127+
{...Platform.OS === 'android' && { accessibilityLabel: "otp-input-hidden" }}
123128
onFocus={handleFocus}
124129
onBlur={handleBlur}
125130
caretHidden={Platform.OS === "ios"}

src/OtpInput/OtpInput.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ColorValue, TextInputProps, TextProps, TextStyle, ViewStyle } from "react-native";
1+
import { ColorValue, TextInputProps, TextProps, TextStyle, ViewStyle, Pressable } from 'react-native';
22

33
export interface OtpInputProps {
44
numberOfDigits?: number;
@@ -16,6 +16,7 @@ export interface OtpInputProps {
1616
disabled?: boolean;
1717
textInputProps?: TextInputProps;
1818
textProps?: TextProps;
19+
buttonProps?: Pressable['props'];
1920
type?: "alpha" | "numeric" | "alphanumeric";
2021
placeholder?: string;
2122
}

0 commit comments

Comments
 (0)