Skip to content

Commit 9412d21

Browse files
authored
Merge pull request #54549 from linhvovan29546/fix/54363-missing-suffix-in-base-text-input-native
2 parents 9c6d3d9 + 74db596 commit 9412d21

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/components/TextInput/BaseTextInput/index.native.tsx

+20-5
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ function BaseTextInput(
6161
multiline = false,
6262
autoCorrect = true,
6363
prefixCharacter = '',
64+
suffixCharacter = '',
6465
inputID,
6566
isMarkdownEnabled = false,
6667
excludedMarkdownStyles = [],
6768
shouldShowClearButton = false,
6869
prefixContainerStyle = [],
6970
prefixStyle = [],
71+
suffixContainerStyle = [],
72+
suffixStyle = [],
7073
contentWidth,
7174
loadingSpinnerStyle,
7275
...props
@@ -87,7 +90,7 @@ function BaseTextInput(
8790
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null
8891
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
8992
const initialValue = value || defaultValue || '';
90-
const initialActiveLabel = !!forceActiveLabel || initialValue.length > 0 || !!prefixCharacter;
93+
const initialActiveLabel = !!forceActiveLabel || initialValue.length > 0 || !!prefixCharacter || !!suffixCharacter;
9194
const isMultiline = multiline || autoGrowHeight;
9295

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

144-
if (!!forceActiveLabel || inputValue.length !== 0 || prefixCharacter) {
147+
if (!!forceActiveLabel || inputValue.length !== 0 || prefixCharacter || suffixCharacter) {
145148
return;
146149
}
147150

148151
animateLabel(styleConst.INACTIVE_LABEL_TRANSLATE_Y, styleConst.INACTIVE_LABEL_SCALE);
149152
isLabelActive.current = false;
150-
}, [animateLabel, forceActiveLabel, prefixCharacter, value]);
153+
}, [animateLabel, forceActiveLabel, prefixCharacter, suffixCharacter, value]);
151154

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

265268
const inputPaddingLeft = !!prefixCharacter && StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(prefixCharacter) + styles.pl1.paddingLeft);
266-
269+
const inputPaddingRight = !!suffixCharacter && StyleUtils.getPaddingRight(StyleUtils.getCharacterPadding(suffixCharacter) + styles.pr1.paddingRight);
267270
return (
268271
<>
269272
<View style={[containerStyles]}>
@@ -351,6 +354,7 @@ function BaseTextInput(
351354
inputStyle,
352355
(!hasLabel || isMultiline) && styles.pv0,
353356
inputPaddingLeft,
357+
inputPaddingRight,
354358
inputProps.secureTextEntry && styles.secureInput,
355359

356360
!isMultiline && {height, lineHeight: undefined},
@@ -380,6 +384,17 @@ function BaseTextInput(
380384
defaultValue={defaultValue}
381385
markdownStyle={markdownStyle}
382386
/>
387+
{!!suffixCharacter && (
388+
<View style={[styles.textInputSuffixWrapper, suffixContainerStyle]}>
389+
<Text
390+
tabIndex={-1}
391+
style={[styles.textInputSuffix, !hasLabel && styles.pv0, styles.pointerEventsNone, suffixStyle]}
392+
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
393+
>
394+
{suffixCharacter}
395+
</Text>
396+
</View>
397+
)}
383398
{isFocused && !isReadOnly && shouldShowClearButton && !!value && <TextInputClearButton onPressButton={() => setValue('')} />}
384399
{!!inputProps.isLoading && (
385400
<ActivityIndicator

0 commit comments

Comments
 (0)