Skip to content

Commit 283063e

Browse files
committed
fix: use StyleSheet.absoluteFill for hidden input
1 parent 6801a6d commit 283063e

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/OtpInput/OtpInput.styles.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const styles = StyleSheet.create({
1919
fontSize: 28,
2020
},
2121
hiddenInput: {
22-
...StyleSheet.absoluteFillObject,
2322
...Platform.select({
2423
ios: {
2524
opacity: 0.02,

src/OtpInput/OtpInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react";
22
import { forwardRef, useImperativeHandle } from "react";
3-
import { Platform, Pressable, Text, TextInput, View } from "react-native";
3+
import { Platform, Pressable, StyleSheet, Text, TextInput, View } from "react-native";
44
import { styles } from "./OtpInput.styles";
55
import { OtpInputProps, OtpInputRef } from "./OtpInput.types";
66
import { VerticalStick } from "./VerticalStick";
@@ -124,7 +124,7 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
124124
onBlur={handleBlur}
125125
caretHidden={Platform.OS === "ios"}
126126
{...textInputProps}
127-
style={[styles.hiddenInput, textInputProps?.style]}
127+
style={[StyleSheet.absoluteFill, styles.hiddenInput, textInputProps?.style]}
128128
/>
129129
</View>
130130
);

src/OtpInput/__tests__/OtpInput.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ describe("OtpInput", () => {
7373
expect(input.props.autoFocus).toBe(false);
7474
});
7575

76+
test("should keep hidden input absolutely positioned to avoid affecting OTP cell spacing", () => {
77+
renderOtpInput();
78+
79+
const input = screen.getByTestId("otp-input-hidden");
80+
81+
expect(input).toHaveStyle({
82+
position: "absolute",
83+
top: 0,
84+
right: 0,
85+
bottom: 0,
86+
left: 0,
87+
});
88+
});
89+
7690
test("should not focus if disabled is true", () => {
7791
renderOtpInput({
7892
disabled: true,

src/OtpInput/__tests__/__snapshots__/OtpInput.test.tsx.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,15 @@ exports[`OtpInput UI should render correctly 1`] = `
399399
[
400400
{
401401
"bottom": 0,
402-
"color": "transparent",
403402
"left": 0,
404-
"opacity": 0.02,
405403
"position": "absolute",
406404
"right": 0,
407405
"top": 0,
408406
},
407+
{
408+
"color": "transparent",
409+
"opacity": 0.02,
410+
},
409411
undefined,
410412
]
411413
}

0 commit comments

Comments
 (0)