Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/OtpInput/OtpInput.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const styles = StyleSheet.create({
fontSize: 28,
},
hiddenInput: {
...StyleSheet.absoluteFillObject,
...Platform.select({
ios: {
opacity: 0.02,
Expand Down
4 changes: 2 additions & 2 deletions src/OtpInput/OtpInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { forwardRef, useImperativeHandle } from "react";
import { Platform, Pressable, Text, TextInput, View } from "react-native";
import { Platform, Pressable, StyleSheet, Text, TextInput, View } from "react-native";
import { styles } from "./OtpInput.styles";
import { OtpInputProps, OtpInputRef } from "./OtpInput.types";
import { VerticalStick } from "./VerticalStick";
Expand Down Expand Up @@ -124,7 +124,7 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
onBlur={handleBlur}
caretHidden={Platform.OS === "ios"}
{...textInputProps}
style={[styles.hiddenInput, textInputProps?.style]}
style={[StyleSheet.absoluteFill, styles.hiddenInput, textInputProps?.style]}
/>
</View>
);
Expand Down
14 changes: 14 additions & 0 deletions src/OtpInput/__tests__/OtpInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ describe("OtpInput", () => {
expect(input.props.autoFocus).toBe(false);
});

test("should keep hidden input absolutely positioned to avoid affecting OTP cell spacing", () => {
renderOtpInput();

const input = screen.getByTestId("otp-input-hidden");

expect(input).toHaveStyle({
position: "absolute",
top: 0,
right: 0,
bottom: 0,
left: 0,
});
});

test("should not focus if disabled is true", () => {
renderOtpInput({
disabled: true,
Expand Down
6 changes: 4 additions & 2 deletions src/OtpInput/__tests__/__snapshots__/OtpInput.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,15 @@ exports[`OtpInput UI should render correctly 1`] = `
[
{
"bottom": 0,
"color": "transparent",
"left": 0,
"opacity": 0.02,
"position": "absolute",
"right": 0,
"top": 0,
},
{
"color": "transparent",
"opacity": 0.02,
},
undefined,
]
}
Expand Down
Loading