Skip to content

Commit 08a5d3c

Browse files
authored
fix: adjust top padding for outlined input without label (#4086)
1 parent 761e3cb commit 08a5d3c

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

example/src/Examples/TextInputExample.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@ const TextInputExample = () => {
661661
error
662662
/>
663663
</View>
664+
<View style={styles.inputContainerStyle}>
665+
<TextInput mode="outlined" placeholder="Outlined without label" />
666+
</View>
664667
<View style={styles.inputContainerStyle}>
665668
<TextInput
666669
mode="outlined"

src/components/TextInput/Addons/Outline.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
ViewStyle,
88
} from 'react-native';
99

10+
import { TextInputLabelProp } from '../types';
11+
1012
type OutlineProps = {
1113
isV3: boolean;
1214
activeColor: string;
@@ -15,11 +17,13 @@ type OutlineProps = {
1517
focused?: boolean;
1618
outlineColor?: string;
1719
roundness?: number;
20+
label?: TextInputLabelProp;
1821
style?: StyleProp<ViewStyle>;
1922
};
2023

2124
export const Outline = ({
2225
isV3,
26+
label,
2327
activeColor,
2428
backgroundColor,
2529
hasActiveOutline,
@@ -33,6 +37,7 @@ export const Outline = ({
3337
pointerEvents="none"
3438
style={[
3539
styles.outline,
40+
!label && styles.noLabelOutline,
3641
// eslint-disable-next-line react-native/no-inline-styles
3742
{
3843
backgroundColor,
@@ -53,4 +58,7 @@ const styles = StyleSheet.create({
5358
top: 6,
5459
bottom: 0,
5560
},
61+
noLabelOutline: {
62+
top: 0,
63+
},
5664
});

src/components/TextInput/TextInputOutlined.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ const TextInputOutlined = ({
113113
theme,
114114
});
115115

116+
const paddingTop = label ? LABEL_PADDING_TOP : 0;
117+
116118
const labelScale = MINIMIZED_LABEL_FONT_SIZE / fontSize;
117119
const fontScale = MAXIMIZED_LABEL_FONT_SIZE / fontSize;
118120

@@ -139,7 +141,7 @@ const TextInputOutlined = ({
139141
}
140142

141143
const minInputHeight =
142-
(dense ? MIN_DENSE_HEIGHT_OUTLINED : MIN_HEIGHT) - LABEL_PADDING_TOP;
144+
(dense ? MIN_DENSE_HEIGHT_OUTLINED : MIN_HEIGHT) - paddingTop;
143145

144146
const inputHeight = calculateInputHeight(labelHeight, height, minInputHeight);
145147

@@ -315,6 +317,7 @@ const TextInputOutlined = ({
315317
<Outline
316318
isV3={isV3}
317319
style={outlineStyle}
320+
label={label}
318321
roundness={roundness}
319322
hasActiveOutline={hasActiveOutline}
320323
focused={parentState.focused}
@@ -327,7 +330,7 @@ const TextInputOutlined = ({
327330
style={[
328331
styles.labelContainer,
329332
{
330-
paddingTop: LABEL_PADDING_TOP,
333+
paddingTop,
331334
minHeight,
332335
},
333336
]}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
616616
"right": 0,
617617
"top": 6,
618618
},
619+
false,
619620
{
620621
"backgroundColor": "rgba(255, 251, 254, 1)",
621622
"borderColor": "rgba(121, 116, 126, 1)",

0 commit comments

Comments
 (0)