Skip to content

Commit

Permalink
fix: use theme background for transparent text inputs (#3980)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Janiczek <[email protected]>
  • Loading branch information
tjaniczek and Tomasz Janiczek authored Aug 2, 2023
1 parent ef12434 commit c3a2dbd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
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

0 comments on commit c3a2dbd

Please sign in to comment.