Skip to content

Commit d9db02e

Browse files
fix(text-input-label-background): custom component background height (#4442)
1 parent 2c721ef commit d9db02e

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

src/components/TextInput/Label/InputLabel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const InputLabel = (props: InputLabelProps) => {
2020
focused,
2121
opacity,
2222
labelLayoutWidth,
23+
labelLayoutHeight,
2324
labelBackground,
2425
label,
2526
labelError,
@@ -157,6 +158,7 @@ const InputLabel = (props: InputLabelProps) => {
157158
{labelBackground?.({
158159
labeled,
159160
labelLayoutWidth,
161+
labelLayoutHeight,
160162
labelStyle,
161163
placeholderStyle,
162164
baseLabelTranslateX,

src/components/TextInput/Label/LabelBackground.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import type { LabelBackgroundProps } from '../types';
77
const LabelBackground = ({
88
labeled,
99
labelLayoutWidth,
10+
labelLayoutHeight,
1011
placeholderStyle,
1112
baseLabelTranslateX,
1213
topPosition,
13-
label,
1414
backgroundColor,
1515
roundness,
1616
labelStyle,
@@ -69,16 +69,15 @@ const LabelBackground = ({
6969
{
7070
top: topPosition + 1,
7171
width: labelLayoutWidth - placeholderStyle.paddingHorizontal,
72+
height: labelLayoutHeight,
7273
backgroundColor,
7374
opacity,
7475
transform: labelTextTransform,
7576
},
7677
]}
7778
numberOfLines={1}
7879
maxFontSizeMultiplier={maxFontSizeMultiplier}
79-
>
80-
{typeof label === 'string' ? label : label?.props.children}
81-
</AnimatedText>,
80+
/>,
8281
];
8382
};
8483

src/components/TextInput/TextInputFlat.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ const TextInputFlat = ({
380380
wiggle={Boolean(parentState.value && labelProps.labelError)}
381381
labelLayoutMeasured={parentState.labelLayout.measured}
382382
labelLayoutWidth={parentState.labelLayout.width}
383+
labelLayoutHeight={parentState.labelLayout.height}
383384
{...labelProps}
384385
/>
385386
) : null}

src/components/TextInput/TextInputOutlined.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ const TextInputOutlined = ({
368368
wiggle={Boolean(parentState.value && labelProps.labelError)}
369369
labelLayoutMeasured={parentState.labelLayout.measured}
370370
labelLayoutWidth={parentState.labelLayout.width}
371+
labelLayoutHeight={parentState.labelLayout.height}
371372
{...labelProps}
372373
labelBackground={LabelBackground}
373374
maxFontSizeMultiplier={rest.maxFontSizeMultiplier}

src/components/TextInput/types.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export type InputLabelProps = {
137137
opacity: number;
138138
labelLayoutMeasured: boolean;
139139
labelLayoutWidth: number;
140+
labelLayoutHeight: number;
140141
inputContainerLayout: { width: number };
141142
labelBackground?: any;
142143
maxFontSizeMultiplier?: number | undefined | null;
@@ -148,6 +149,7 @@ export type LabelBackgroundProps = {
148149
labelStyle: any;
149150
labeled: Animated.Value;
150151
labelLayoutWidth: number;
152+
labelLayoutHeight: number;
151153
maxFontSizeMultiplier?: number | undefined | null;
152154
theme?: ThemeProp;
153155
} & LabelProps;

src/components/__tests__/__snapshots__/TextInput.test.tsx.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
10841084
"fontFamily": "System",
10851085
"fontSize": 16,
10861086
"fontWeight": undefined,
1087+
"height": 0,
10871088
"left": 8,
10881089
"letterSpacing": 0.15,
10891090
"lineHeight": undefined,
@@ -1111,9 +1112,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
11111112
}
11121113
}
11131114
testID="text-input-outlined-label-background"
1114-
>
1115-
Outline Input
1116-
</Text>
1115+
/>
11171116
<Text
11181117
collapsable={false}
11191118
maxFontSizeMultiplier={1.5}

0 commit comments

Comments
 (0)