Skip to content

Commit e9f614a

Browse files
committedDec 25, 2024··
fix: missing suffix in native BaseTextInput
1 parent ad99c20 commit e9f614a

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
@@ -60,12 +60,15 @@ function BaseTextInput(
6060
multiline = false,
6161
autoCorrect = true,
6262
prefixCharacter = '',
63+
suffixCharacter = '',
6364
inputID,
6465
isMarkdownEnabled = false,
6566
excludedMarkdownStyles = [],
6667
shouldShowClearButton = false,
6768
prefixContainerStyle = [],
6869
prefixStyle = [],
70+
suffixContainerStyle = [],
71+
suffixStyle = [],
6972
contentWidth,
7073
loadingSpinnerStyle,
7174
...props
@@ -86,7 +89,7 @@ function BaseTextInput(
8689
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null
8790
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
8891
const initialValue = value || defaultValue || '';
89-
const initialActiveLabel = !!forceActiveLabel || initialValue.length > 0 || !!prefixCharacter;
92+
const initialActiveLabel = !!forceActiveLabel || initialValue.length > 0 || !!prefixCharacter || !!suffixCharacter;
9093
const isMultiline = multiline || autoGrowHeight;
9194

9295
const [isFocused, setIsFocused] = useState(false);
@@ -140,13 +143,13 @@ function BaseTextInput(
140143
const deactivateLabel = useCallback(() => {
141144
const inputValue = value ?? '';
142145

143-
if (!!forceActiveLabel || inputValue.length !== 0 || prefixCharacter) {
146+
if (!!forceActiveLabel || inputValue.length !== 0 || prefixCharacter || suffixCharacter) {
144147
return;
145148
}
146149

147150
animateLabel(styleConst.INACTIVE_LABEL_TRANSLATE_Y, styleConst.INACTIVE_LABEL_SCALE);
148151
isLabelActive.current = false;
149-
}, [animateLabel, forceActiveLabel, prefixCharacter, value]);
152+
}, [animateLabel, forceActiveLabel, prefixCharacter, suffixCharacter, value]);
150153

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

263266
const inputPaddingLeft = !!prefixCharacter && StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(prefixCharacter) + styles.pl1.paddingLeft);
264-
267+
const inputPaddingRight = !!suffixCharacter && StyleUtils.getPaddingRight(StyleUtils.getCharacterPadding(suffixCharacter) + styles.pr1.paddingRight);
265268
return (
266269
<>
267270
<View style={[containerStyles]}>
@@ -349,6 +352,7 @@ function BaseTextInput(
349352
inputStyle,
350353
(!hasLabel || isMultiline) && styles.pv0,
351354
inputPaddingLeft,
355+
inputPaddingRight,
352356
inputProps.secureTextEntry && styles.secureInput,
353357

354358
!isMultiline && {height, lineHeight: undefined},
@@ -378,6 +382,17 @@ function BaseTextInput(
378382
defaultValue={defaultValue}
379383
markdownStyle={markdownStyle}
380384
/>
385+
{!!suffixCharacter && (
386+
<View style={[styles.textInputSuffixWrapper, suffixContainerStyle]}>
387+
<Text
388+
tabIndex={-1}
389+
style={[styles.textInputSuffix, !hasLabel && styles.pv0, styles.pointerEventsNone, suffixStyle]}
390+
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
391+
>
392+
{suffixCharacter}
393+
</Text>
394+
</View>
395+
)}
381396
{isFocused && !isReadOnly && shouldShowClearButton && !!value && <TextInputClearButton onPressButton={() => setValue('')} />}
382397
{!!inputProps.isLoading && (
383398
<ActivityIndicator

0 commit comments

Comments
 (0)
Please sign in to comment.