Skip to content

Commit e509bf8

Browse files
authored
fix: outlined input error border width (#2975)
1 parent 85d679e commit e509bf8

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

example/src/Examples/TextInputExample.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,13 @@ const TextInputExample = () => {
468468
label="Custom rounded input"
469469
/>
470470
</View>
471+
<View style={styles.inputContainerStyle}>
472+
<TextInput
473+
mode="outlined"
474+
label="Outlined text input with error"
475+
error
476+
/>
477+
</View>
471478
</ScreenWrapper>
472479
</TextInputAvoidingView>
473480
);

src/components/TextInput/TextInputOutlined.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ class TextInputOutlined extends React.Component<ChildTextInputProps> {
295295
<Outline
296296
theme={theme}
297297
hasActiveOutline={hasActiveOutline}
298+
focused={parentState.focused}
298299
activeColor={activeColor}
299300
outlineColor={outlineColor}
300301
backgroundColor={backgroundColor}
@@ -314,6 +315,7 @@ class TextInputOutlined extends React.Component<ChildTextInputProps> {
314315
labelBackground={LabelBackground}
315316
/>
316317
{render?.({
318+
testID: 'text-input-outlined',
317319
...rest,
318320
ref: innerRef,
319321
onChangeText,
@@ -365,6 +367,7 @@ export default TextInputOutlined;
365367
type OutlineProps = {
366368
activeColor: string;
367369
hasActiveOutline?: boolean;
370+
focused?: boolean;
368371
outlineColor?: string;
369372
backgroundColor: ColorValue;
370373
theme: ReactNativePaper.Theme;
@@ -375,17 +378,19 @@ const Outline = ({
375378
hasActiveOutline,
376379
activeColor,
377380
outlineColor,
381+
focused,
378382
backgroundColor,
379383
}: OutlineProps) => (
380384
<View
385+
testID="text-input-outline"
381386
pointerEvents="none"
382387
style={[
383388
styles.outline,
384389
// eslint-disable-next-line react-native/no-inline-styles
385390
{
386391
backgroundColor,
387392
borderRadius: theme.roundness,
388-
borderWidth: hasActiveOutline ? 2 : 1,
393+
borderWidth: focused ? 2 : 1,
389394
borderColor: hasActiveOutline ? activeColor : outlineColor,
390395
},
391396
]}

src/components/__tests__/TextInput.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { StyleSheet } from 'react-native';
3-
import { render } from 'react-native-testing-library';
3+
import { fireEvent, render } from 'react-native-testing-library';
44
import TextInput from '../TextInput/TextInput';
55
import { red500 } from '../../styles/colors';
66

@@ -108,3 +108,43 @@ it('correctly applies height to multiline Outline TextInput', () => {
108108

109109
expect(toJSON()).toMatchSnapshot();
110110
});
111+
112+
it('correctly applies error state Outline TextInput', () => {
113+
const { getByTestId } = render(
114+
<TextInput
115+
mode="outlined"
116+
label="Outline Input with error"
117+
placeholder="Type Something"
118+
value={'Some test value'}
119+
error
120+
/>
121+
);
122+
123+
const outline = getByTestId('text-input-outline');
124+
expect(outline.props.style).toEqual(
125+
expect.arrayContaining([expect.objectContaining({ borderWidth: 1 })])
126+
);
127+
});
128+
129+
it('correctly applies focused state Outline TextInput', () => {
130+
const { getByTestId } = render(
131+
<TextInput
132+
mode="outlined"
133+
label="Outline Input with error"
134+
placeholder="Type Something"
135+
value={'Some test value'}
136+
error
137+
/>
138+
);
139+
140+
const outline = getByTestId('text-input-outline');
141+
expect(outline.props.style).toEqual(
142+
expect.arrayContaining([expect.objectContaining({ borderWidth: 1 })])
143+
);
144+
145+
fireEvent(getByTestId('text-input-outlined'), 'focus');
146+
147+
expect(outline.props.style).toEqual(
148+
expect.arrayContaining([expect.objectContaining({ borderWidth: 2 })])
149+
);
150+
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
201201
},
202202
]
203203
}
204+
testID="text-input-outline"
204205
/>
205206
<View
206207
style={
@@ -392,6 +393,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
392393
],
393394
]
394395
}
396+
testID="text-input-outlined"
395397
underlineColorAndroid="transparent"
396398
value="Some test value"
397399
/>

0 commit comments

Comments
 (0)