Skip to content

Commit

Permalink
fix: adjust top padding for outlined input without label (#4086)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak authored Sep 18, 2023
1 parent 761e3cb commit 08a5d3c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions example/src/Examples/TextInputExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ const TextInputExample = () => {
error
/>
</View>
<View style={styles.inputContainerStyle}>
<TextInput mode="outlined" placeholder="Outlined without label" />
</View>
<View style={styles.inputContainerStyle}>
<TextInput
mode="outlined"
Expand Down
8 changes: 8 additions & 0 deletions src/components/TextInput/Addons/Outline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
ViewStyle,
} from 'react-native';

import { TextInputLabelProp } from '../types';

type OutlineProps = {
isV3: boolean;
activeColor: string;
Expand All @@ -15,11 +17,13 @@ type OutlineProps = {
focused?: boolean;
outlineColor?: string;
roundness?: number;
label?: TextInputLabelProp;
style?: StyleProp<ViewStyle>;
};

export const Outline = ({
isV3,
label,
activeColor,
backgroundColor,
hasActiveOutline,
Expand All @@ -33,6 +37,7 @@ export const Outline = ({
pointerEvents="none"
style={[
styles.outline,
!label && styles.noLabelOutline,
// eslint-disable-next-line react-native/no-inline-styles
{
backgroundColor,
Expand All @@ -53,4 +58,7 @@ const styles = StyleSheet.create({
top: 6,
bottom: 0,
},
noLabelOutline: {
top: 0,
},
});
7 changes: 5 additions & 2 deletions src/components/TextInput/TextInputOutlined.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ const TextInputOutlined = ({
theme,
});

const paddingTop = label ? LABEL_PADDING_TOP : 0;

const labelScale = MINIMIZED_LABEL_FONT_SIZE / fontSize;
const fontScale = MAXIMIZED_LABEL_FONT_SIZE / fontSize;

Expand All @@ -139,7 +141,7 @@ const TextInputOutlined = ({
}

const minInputHeight =
(dense ? MIN_DENSE_HEIGHT_OUTLINED : MIN_HEIGHT) - LABEL_PADDING_TOP;
(dense ? MIN_DENSE_HEIGHT_OUTLINED : MIN_HEIGHT) - paddingTop;

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

Expand Down Expand Up @@ -315,6 +317,7 @@ const TextInputOutlined = ({
<Outline
isV3={isV3}
style={outlineStyle}
label={label}
roundness={roundness}
hasActiveOutline={hasActiveOutline}
focused={parentState.focused}
Expand All @@ -327,7 +330,7 @@ const TextInputOutlined = ({
style={[
styles.labelContainer,
{
paddingTop: LABEL_PADDING_TOP,
paddingTop,
minHeight,
},
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
"right": 0,
"top": 6,
},
false,
{
"backgroundColor": "rgba(255, 251, 254, 1)",
"borderColor": "rgba(121, 116, 126, 1)",
Expand Down

0 comments on commit 08a5d3c

Please sign in to comment.