Skip to content

Commit c09c1bd

Browse files
authored
Merge pull request #215 from DogusErdem/fix/placeholder-position
fix: Fixed the position of the placeholder and label.
2 parents 76eb9f5 + 7930afe commit c09c1bd

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/components/TextInput/TextInput.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,14 @@ const TextInput: FCCWD<TextInputProps & RNTextInputProps> = (
161161
const topInterpolate = interpolate(
162162
textInputOffset.value,
163163
[0, 1],
164-
[variant === 'filled' ? 2 : -labelStyles[size].focused.lineHeight + labelStyles[size].focused.lineHeight / 2,
165-
sizeStyles[size].paddingVertical],
164+
[(variant === 'filled' && label)
165+
? 2 : -labelStyles[size].focused.lineHeight + labelStyles[size].focused.lineHeight / 2,
166+
sizeStyles[size].paddingVertical],
166167
);
167168
const leftInterpolate = interpolate(
168169
textInputOffset.value,
169170
[0, 1],
170-
[variant === 'outlined' ? 4 : 0, 0],
171+
[(variant === 'outlined' && label) ? 4 : 0, 0],
171172
);
172173
return {
173174
fontSize,
@@ -199,7 +200,7 @@ const TextInput: FCCWD<TextInputProps & RNTextInputProps> = (
199200
};
200201

201202
useEffect(() => {
202-
if (!props?.value && !isFocused) {
203+
if (!props.defaultValue && !props.placeholder && !props.value && !isFocused) {
203204
textInputOffset.value = withTiming(1);
204205
setIsFocused(false);
205206
setCounts(0);
@@ -234,7 +235,7 @@ const TextInput: FCCWD<TextInputProps & RNTextInputProps> = (
234235
)}
235236

236237
<View style={{ flex: 1, flexDirection: 'row' }}>
237-
{variant === 'outlined' && (
238+
{(variant === 'outlined' && label) && (
238239
<Animated.View style={[{ position: 'absolute',
239240
width: labelLayout.width + 8,
240241
height: 2,
@@ -246,7 +247,7 @@ const TextInput: FCCWD<TextInputProps & RNTextInputProps> = (
246247
ref={inputRef}
247248
editable={editable}
248249
style={[{
249-
marginTop: variant === 'filled' ? fontStyles[size].lineHeight / 2 : 0,
250+
marginTop: (variant === 'filled' && label) ? fontStyles[size].lineHeight / 2 : 0,
250251
fontSize: fontStyles[size].fontSize,
251252
fontFamily: labelStyles[size].default.fontFamily,
252253
lineHeight: sizeStyles[size].lineHeight,

0 commit comments

Comments
 (0)