Skip to content

Commit

Permalink
fix(text-input): remove text duplication of label as component (#4115)
Browse files Browse the repository at this point in the history
Co-authored-by: Lev Shapiro <levshapiro@MacBook-Air-2.local>
  • Loading branch information
Lev-Shapiro and Lev Shapiro authored Oct 12, 2023
1 parent d698282 commit 2bb6256
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions example/src/Examples/TextInputExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const initialState: State = {
largeText: '',
flatTextPassword: 'Password',
outlinedLargeText: '',
outlinedCustomLabel: '',
outlinedTextPassword: '',
nameNoPadding: '',
customStyleText: '',
Expand Down Expand Up @@ -89,6 +90,7 @@ const TextInputExample = () => {
largeText,
flatTextPassword,
outlinedLargeText,
outlinedCustomLabel,
outlinedTextPassword,
nameNoPadding,
customStyleText,
Expand Down Expand Up @@ -290,6 +292,16 @@ const TextInputExample = () => {
/>
}
/>
<TextInput
mode="outlined"
style={[styles.inputContainerStyle, styles.fontSize]}
label={<Text style={styles.inputLabelText}>Custom label</Text>}
placeholder="Type something"
value={outlinedCustomLabel}
onChangeText={(outlinedCustomLabel) =>
inputActionHandler('outlinedCustomLabel', outlinedCustomLabel)
}
/>
<TextInput
mode="outlined"
style={[styles.inputContainerStyle, styles.fontSize]}
Expand Down Expand Up @@ -812,6 +824,9 @@ const styles = StyleSheet.create({
flex: 1,
marginLeft: 4,
},
inputLabelText: {
color: MD3Colors.tertiary70,
},
});

export default TextInputExample;
3 changes: 2 additions & 1 deletion example/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Platform } from 'react-native';

import ExpoMaterial3ThemeModule from '@pchmn/expo-material3-theme/build/ExpoMaterial3ThemeModule';
import { MD3LightTheme, MD3DarkTheme, MD3Theme } from 'react-native-paper';
import { MD3DarkTheme, MD3LightTheme, MD3Theme } from 'react-native-paper';

type ReducerAction<T extends keyof State> = {
payload: State[T];
Expand All @@ -24,6 +24,7 @@ export type State = {
largeText: string;
flatTextPassword: string;
outlinedLargeText: string;
outlinedCustomLabel: string;
outlinedTextPassword: string;
nameNoPadding: string;
customStyleText: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/Label/InputLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Animated, StyleSheet, Dimensions } from 'react-native';
import { Animated, Dimensions, StyleSheet } from 'react-native';

import AnimatedText from '../../Typography/AnimatedText';
import type { InputLabelProps } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/Label/LabelBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const LabelBackground = ({
numberOfLines={1}
maxFontSizeMultiplier={maxFontSizeMultiplier}
>
{label}
{typeof label === 'string' ? label : label?.props.children}
</AnimatedText>,
];
};
Expand Down

0 comments on commit 2bb6256

Please sign in to comment.