Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use theme background for transparent text inputs #3980

Merged
merged 1 commit into from
Aug 2, 2023
Merged
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: 1 addition & 0 deletions src/components/TextInput/Label/InputLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const InputLabel = (props: InputLabelProps) => {
backgroundColor,
roundness,
maxFontSizeMultiplier: maxFontSizeMultiplier,
testID,
})}
<AnimatedText
variant="bodySmall"
Expand Down
2 changes: 2 additions & 0 deletions src/components/TextInput/Label/LabelBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const LabelBackground = ({
roundness,
labelStyle,
maxFontSizeMultiplier,
testID,
}: LabelBackgroundProps) => {
const opacity = labeled.interpolate({
inputRange: [0, 0.6],
Expand Down Expand Up @@ -60,6 +61,7 @@ const LabelBackground = ({
roundedEdgeCover,
<AnimatedText
key="labelBackground-text"
testID={`${testID}-label-background`}
style={[
placeholderStyle,
labelStyle,
Expand Down
7 changes: 6 additions & 1 deletion src/components/TextInput/TextInputOutlined.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ const TextInputOutlined = ({
paddingHorizontal: INPUT_PADDING_HORIZONTAL,
};

const labelBackgroundColor: ColorValue =
backgroundColor === 'transparent'
? theme.colors.background
: backgroundColor;

const labelProps = {
label,
onLayoutAnimatedText,
Expand All @@ -204,7 +209,7 @@ const TextInputOutlined = ({
hasActiveOutline,
activeColor,
placeholderColor,
backgroundColor: backgroundColor as ColorValue,
backgroundColor: labelBackgroundColor,
errorColor,
labelTranslationXOffset,
roundness,
Expand Down
29 changes: 28 additions & 1 deletion src/components/__tests__/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StyleSheet, Text, Platform, I18nManager } from 'react-native';
import { fireEvent, render } from '@testing-library/react-native';
import color from 'color';

import { getTheme } from '../../core/theming';
import { DefaultTheme, getTheme, ThemeProvider } from '../../core/theming';
import { red500 } from '../../styles/themes/v2/colors';
import {
getFlatInputColors,
Expand Down Expand Up @@ -355,6 +355,33 @@ it('calls onLayout on right-side affix adornment', () => {
})
);

it("correctly applies theme background to label when input's background is transparent", () => {
const backgroundColor = 'transparent';
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: 'pink',
},
};

const { getByTestId } = render(
<ThemeProvider theme={theme}>
<TextInput
mode="outlined"
label="Transparent input"
value={'Some test value'}
style={{ backgroundColor }}
testID={'transparent-example'}
/>
</ThemeProvider>
);

expect(getByTestId('transparent-example-label-background')).toHaveStyle({
backgroundColor: 'pink',
});
});

describe('maxFontSizeMultiplier', () => {
const createInput = (
type: Exclude<Props['mode'], undefined>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
"writingDirection": "ltr",
}
}
testID="text-input-outlined-label-background"
>
Outline Input
</Text>
Expand Down