Skip to content

Commit

Permalink
Merge pull request Expensify#54549 from linhvovan29546/fix/54363-miss…
Browse files Browse the repository at this point in the history
…ing-suffix-in-base-text-input-native
  • Loading branch information
iwiznia authored Dec 27, 2024
2 parents 9c6d3d9 + 74db596 commit 9412d21
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ function BaseTextInput(
multiline = false,
autoCorrect = true,
prefixCharacter = '',
suffixCharacter = '',
inputID,
isMarkdownEnabled = false,
excludedMarkdownStyles = [],
shouldShowClearButton = false,
prefixContainerStyle = [],
prefixStyle = [],
suffixContainerStyle = [],
suffixStyle = [],
contentWidth,
loadingSpinnerStyle,
...props
Expand All @@ -87,7 +90,7 @@ function BaseTextInput(
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const initialValue = value || defaultValue || '';
const initialActiveLabel = !!forceActiveLabel || initialValue.length > 0 || !!prefixCharacter;
const initialActiveLabel = !!forceActiveLabel || initialValue.length > 0 || !!prefixCharacter || !!suffixCharacter;
const isMultiline = multiline || autoGrowHeight;

const [isFocused, setIsFocused] = useState(false);
Expand Down Expand Up @@ -141,13 +144,13 @@ function BaseTextInput(
const deactivateLabel = useCallback(() => {
const inputValue = value ?? '';

if (!!forceActiveLabel || inputValue.length !== 0 || prefixCharacter) {
if (!!forceActiveLabel || inputValue.length !== 0 || prefixCharacter || suffixCharacter) {
return;
}

animateLabel(styleConst.INACTIVE_LABEL_TRANSLATE_Y, styleConst.INACTIVE_LABEL_SCALE);
isLabelActive.current = false;
}, [animateLabel, forceActiveLabel, prefixCharacter, value]);
}, [animateLabel, forceActiveLabel, prefixCharacter, suffixCharacter, value]);

const onFocus = (event: NativeSyntheticEvent<TextInputFocusEventData>) => {
inputProps.onFocus?.(event);
Expand Down Expand Up @@ -250,7 +253,7 @@ function BaseTextInput(
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null, and errorText can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const inputHelpText = errorText || hint;
const placeholderValue = !!prefixCharacter || isFocused || !hasLabel || (hasLabel && forceActiveLabel) ? placeholder : undefined;
const placeholderValue = !!prefixCharacter || !!suffixCharacter || isFocused || !hasLabel || (hasLabel && forceActiveLabel) ? placeholder : undefined;
const newTextInputContainerStyles: StyleProp<ViewStyle> = StyleSheet.flatten([
styles.textInputContainer,
textInputContainerStyles,
Expand All @@ -263,7 +266,7 @@ function BaseTextInput(
]);

const inputPaddingLeft = !!prefixCharacter && StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(prefixCharacter) + styles.pl1.paddingLeft);

const inputPaddingRight = !!suffixCharacter && StyleUtils.getPaddingRight(StyleUtils.getCharacterPadding(suffixCharacter) + styles.pr1.paddingRight);
return (
<>
<View style={[containerStyles]}>
Expand Down Expand Up @@ -351,6 +354,7 @@ function BaseTextInput(
inputStyle,
(!hasLabel || isMultiline) && styles.pv0,
inputPaddingLeft,
inputPaddingRight,
inputProps.secureTextEntry && styles.secureInput,

!isMultiline && {height, lineHeight: undefined},
Expand Down Expand Up @@ -380,6 +384,17 @@ function BaseTextInput(
defaultValue={defaultValue}
markdownStyle={markdownStyle}
/>
{!!suffixCharacter && (
<View style={[styles.textInputSuffixWrapper, suffixContainerStyle]}>
<Text
tabIndex={-1}
style={[styles.textInputSuffix, !hasLabel && styles.pv0, styles.pointerEventsNone, suffixStyle]}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
>
{suffixCharacter}
</Text>
</View>
)}
{isFocused && !isReadOnly && shouldShowClearButton && !!value && <TextInputClearButton onPressButton={() => setValue('')} />}
{!!inputProps.isLoading && (
<ActivityIndicator
Expand Down

0 comments on commit 9412d21

Please sign in to comment.