Skip to content

Commit d1fa26b

Browse files
authored
fix(text-input): keep a TextInput without a label visible while empty (#5191)
A TextInput without a label showed only its outline while empty and unfocused: the label's float opacity also hid the input and its placeholder. That opacity now applies only when a label is set. Fixes #5187
1 parent 96af73b commit d1fa26b

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎src/components/TextInput/hooks.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,11 @@ export const useTextInput = (props: TextInputProps): TextInputHookReturn => {
453453
selectionColor,
454454
cursorColor,
455455
animatedActiveOutlineStyles: undefined,
456-
animatedContainerStyle: animation.animatedContainerStyle,
456+
// The input only fades out while a label rests in its place; without a
457+
// label the input and its placeholder stay visible.
458+
animatedContainerStyle: props.label
459+
? animation.animatedContainerStyle
460+
: undefined,
457461
placeholder,
458462
counterText,
459463
accessibilityProps,

‎src/components/__tests__/TextInput.test.tsx‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,35 @@ it('shows placeholder on multiline TextInput when focused', async () => {
979979
);
980980
});
981981

982+
it.each(['filled', 'outlined'] as const)(
983+
'keeps an empty, unfocused %s TextInput without a label visible',
984+
async (variant) => {
985+
await render(
986+
<TextInput
987+
variant={variant}
988+
value=""
989+
onChangeText={() => {}}
990+
placeholder="Search for plugins..."
991+
/>
992+
);
993+
994+
expect(screen.getByPlaceholderText('Search for plugins...')).toBeVisible();
995+
}
996+
);
997+
998+
it('hides the input of an empty, unfocused TextInput while its label rests in place', async () => {
999+
await render(
1000+
<TextInput
1001+
label="Email"
1002+
value=""
1003+
onChangeText={() => {}}
1004+
testID="tf-input"
1005+
/>
1006+
);
1007+
1008+
expect(screen.getByTestId('tf-input')).not.toBeVisible();
1009+
});
1010+
9821011
it('does not expose the placeholder string again after the TextInput loses focus', async () => {
9831012
await render(
9841013
<TextInput

0 commit comments

Comments
 (0)