Skip to content

Commit 89e38fd

Browse files
committed
Add 'shouldLabelStayOnSingleLine' prop to BaseTextInput and TextInputLabel components
This update introduces a new prop to control the label's behavior in multiline inputs, ensuring it can remain on a single line and ellipsize as needed. The prop has been added to the relevant types, implementations, and usage in AddAIRulePage and EditAIRulePage components.
1 parent 143a78d commit 89e38fd

8 files changed

Lines changed: 20 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function BaseTextInput({
6464
shouldRenderHintAsHTML = false,
6565
onInputChange = () => {},
6666
multiline = false,
67+
shouldLabelStayOnSingleLine = false,
6768
autoCorrect = true,
6869
prefixCharacter = '',
6970
suffixCharacter = '',
@@ -345,6 +346,7 @@ function BaseTextInput({
345346
labelScale={labelScale}
346347
for={inputProps.nativeID}
347348
isMultiline={isMultiline}
349+
shouldLabelStayOnSingleLine={shouldLabelStayOnSingleLine}
348350
/>
349351
) : null}
350352
{hiddenLabel}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function BaseTextInput({
6363
shouldRenderHintAsHTML = false,
6464
onInputChange = () => {},
6565
multiline = false,
66+
shouldLabelStayOnSingleLine = false,
6667
shouldInterceptSwipe = false,
6768
autoCorrect = true,
6869
prefixCharacter = '',
@@ -392,6 +393,7 @@ function BaseTextInput({
392393
labelScale={labelScale}
393394
for={inputProps.nativeID}
394395
isMultiline={isMultiline}
396+
shouldLabelStayOnSingleLine={shouldLabelStayOnSingleLine}
395397
/>
396398
</>
397399
) : null}

src/components/TextInput/BaseTextInput/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ type CustomBaseTextInputProps = ForwardedFSClassProps &
117117
/** Indicate whether input is multiline */
118118
multiline?: boolean;
119119

120+
/** Force the floating label to render on a single line and ellipsize even when the input is multiline */
121+
shouldLabelStayOnSingleLine?: boolean;
122+
120123
/** Set the default value to the input if there is a valid saved value */
121124
shouldUseDefaultValue?: boolean;
122125

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import Animated, {useAnimatedStyle} from 'react-native-reanimated';
33
import useThemeStyles from '@hooks/useThemeStyles';
44
import type TextInputLabelProps from './types';
55

6-
function TextInputLabel({label, labelScale, labelTranslateY, isMultiline}: TextInputLabelProps) {
6+
function TextInputLabel({label, labelScale, labelTranslateY, isMultiline, shouldLabelStayOnSingleLine}: TextInputLabelProps) {
77
const styles = useThemeStyles();
8+
const shouldClipToSingleLine = !isMultiline || shouldLabelStayOnSingleLine;
89

910
const animatedStyle = useAnimatedStyle(() => styles.textInputLabelTransformation(labelTranslateY, labelScale));
1011
const animatedStyleForText = useAnimatedStyle(() => styles.textInputLabelTransformation(labelTranslateY, labelScale, true));
@@ -15,8 +16,8 @@ function TextInputLabel({label, labelScale, labelTranslateY, isMultiline}: TextI
1516
accessible={false}
1617
accessibilityElementsHidden
1718
importantForAccessibility="no"
18-
numberOfLines={!isMultiline ? 1 : undefined}
19-
ellipsizeMode={!isMultiline ? 'tail' : undefined}
19+
numberOfLines={shouldClipToSingleLine ? 1 : undefined}
20+
ellipsizeMode={shouldClipToSingleLine ? 'tail' : undefined}
2021
allowFontScaling={false}
2122
style={[styles.textInputLabel, animatedStyleForText]}
2223
>

src/components/TextInput/TextInputLabel/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import CONST from '@src/CONST';
77
import textRef from '@src/types/utils/textRef';
88
import type TextInputLabelProps from './types';
99

10-
function TextInputLabel({for: inputId = '', label, labelTranslateY, labelScale, isMultiline}: TextInputLabelProps) {
10+
function TextInputLabel({for: inputId = '', label, labelTranslateY, labelScale, isMultiline, shouldLabelStayOnSingleLine}: TextInputLabelProps) {
11+
const shouldClipToSingleLine = !isMultiline || shouldLabelStayOnSingleLine;
1112
const styles = useThemeStyles();
1213
const labelRef = useRef<Text | HTMLFormElement>(null);
1314

@@ -23,8 +24,8 @@ function TextInputLabel({for: inputId = '', label, labelTranslateY, labelScale,
2324

2425
return (
2526
<Animated.Text
26-
numberOfLines={!isMultiline ? 1 : undefined}
27-
ellipsizeMode={!isMultiline ? 'tail' : undefined}
27+
numberOfLines={shouldClipToSingleLine ? 1 : undefined}
28+
ellipsizeMode={shouldClipToSingleLine ? 'tail' : undefined}
2829
ref={textRef(labelRef)}
2930
role={CONST.ROLE.PRESENTATION}
3031
accessible={false}

src/components/TextInput/TextInputLabel/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type TextInputLabelProps = {
1313
/** Whether the input is multiline */
1414
isMultiline?: boolean;
1515

16+
/** Force the floating label to render on a single line and ellipsize even when the input is multiline */
17+
shouldLabelStayOnSingleLine?: boolean;
18+
1619
/** For attribute for label */
1720
for?: string;
1821
};

src/pages/workspace/rules/AIRules/AddAIRulePage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function AddAIRulePage({
9494
role={CONST.ROLE.PRESENTATION}
9595
onKeyPress={handleKeyPress}
9696
multiline
97+
shouldLabelStayOnSingleLine
9798
containerStyles={[styles.flex1]}
9899
touchableInputWrapperStyle={[styles.flex1]}
99100
textInputContainerStyles={[styles.flex1]}

src/pages/workspace/rules/AIRules/EditAIRulePage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function EditAIRulePage({
141141
onKeyPress={handleKeyPress}
142142
defaultValue={aiRule.prompt}
143143
multiline
144+
shouldLabelStayOnSingleLine
144145
containerStyles={[styles.flex1]}
145146
touchableInputWrapperStyle={[styles.flex1]}
146147
textInputContainerStyles={[styles.flex1]}

0 commit comments

Comments
 (0)