Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 695f000

Browse files
author
Xiaozhou Li
committed
InputField new option: showValidationError
1 parent a7a859e commit 695f000

8 files changed

Lines changed: 62 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ exports[`The Form component should render with a form item 1`] = `
4242
labelLayoutWidth="1/1"
4343
labelWidthBreakpoint="sm"
4444
onChangeHandler={[MockFunction]}
45+
showValidationError={true}
4546
staticField={false}
4647
type="text"
4748
value={null}
@@ -51,6 +52,7 @@ exports[`The Form component should render with a form item 1`] = `
5152
labelLayoutWidth="1/1"
5253
labelWidthBreakpoint="sm"
5354
onChangeHandler={[MockFunction]}
55+
showValidationError={true}
5456
staticField={false}
5557
type="text"
5658
value={null}
@@ -60,6 +62,7 @@ exports[`The Form component should render with a form item 1`] = `
6062
labelLayoutWidth="1/1"
6163
labelWidthBreakpoint="sm"
6264
onChangeHandler={[MockFunction]}
65+
showValidationError={true}
6366
staticField={false}
6467
type="text"
6568
value={null}
@@ -69,6 +72,7 @@ exports[`The Form component should render with a form item 1`] = `
6972
labelLayoutWidth="1/1"
7073
labelWidthBreakpoint="sm"
7174
onChangeHandler={[MockFunction]}
75+
showValidationError={true}
7276
staticField={false}
7377
touched={false}
7478
>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`The InputField component should render 1`] = `
66
labelLayoutWidth="1/1"
77
labelWidthBreakpoint="sm"
88
onChangeHandler={[MockFunction]}
9+
showValidationError={true}
910
staticField={false}
1011
type="text"
1112
value="Test input"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exports[`The PopupPrompt component should render a prompt popup 1`] = `
1515
labelLayoutWidth="1/1"
1616
labelWidthBreakpoint="sm"
1717
onChangeHandler={[Function]}
18+
showValidationError={true}
1819
staticField={false}
1920
type="text"
2021
/>

src/components/__tests__/input_field.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('The InputField component', () => {
3434
labelLayoutWidth: '1/1',
3535
labelWidthBreakpoint: 'sm',
3636
onChangeHandler: props.onChangeHandler,
37+
showValidationError: true,
3738
staticField: true,
3839
value: 'Test input',
3940
});
@@ -48,6 +49,7 @@ describe('The InputField component', () => {
4849
labelLayoutWidth: '1/1',
4950
labelWidthBreakpoint: 'sm',
5051
onChangeHandler: props.onChangeHandler,
52+
showValidationError: true,
5153
staticField: false,
5254
value: 'Test input',
5355
});

src/components/input_field.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class InputField extends React.Component<OldInputFieldProps, {}> {
8484
labelLayoutWidth: '1/1',
8585
labelWidthBreakpoint: 'sm',
8686
staticField: false,
87+
showValidationError: true,
8788
};
8889

8990
render() {

src/components/input_fields/__tests__/__snapshots__/input_field_wrapper.test.tsx.snap

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,46 @@ exports[`The input field wrapper component should render a wrapper without any o
100100
</div>
101101
</div>
102102
`;
103+
104+
exports[`The input field wrapper component should render a wrapper without the validation error 1`] = `
105+
<div
106+
className="input-field layout test-input-class"
107+
>
108+
<InputFieldLabel
109+
id="testInputId"
110+
infoLinkURL="http://info.url"
111+
infoText="Click for more info"
112+
label="Test Input Label"
113+
labelLayoutWidth="1/2"
114+
labelWidthBreakpoint="xs"
115+
preLabelElement="*"
116+
/>
117+
<div
118+
className="layout__item u-fill layout__item--middle test-input-class text-center"
119+
>
120+
<div
121+
className="input-container layout layout--gutter-xs"
122+
>
123+
<div
124+
className="input-wrapper-children layout__item u-fill"
125+
>
126+
<div>
127+
child
128+
</div>
129+
</div>
130+
<div
131+
className="layout__item u-fit input-field__field-addition"
132+
>
133+
<Icon(RequiredIcon) />
134+
</div>
135+
</div>
136+
</div>
137+
<div
138+
className="layout__item u-fit input-children"
139+
>
140+
<div>
141+
input child
142+
</div>
143+
</div>
144+
</div>
145+
`;

src/components/input_fields/__tests__/input_field_wrapper.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('The input field wrapper component', () => {
2424
required: true,
2525
submitted: false,
2626
validationError: 'A validation error!',
27+
showValidationError: true,
2728
touched: true,
2829
children: <div>child</div>,
2930
inputChildren: <div>input child</div>,
@@ -50,4 +51,9 @@ describe('The input field wrapper component', () => {
5051
wrapper = shallow(<InputFieldWrapper {...props} />);
5152
expect(wrapper).toMatchSnapshot();
5253
});
54+
55+
it('should render a wrapper without the validation error', () => {
56+
wrapper.setProps({ showValidationError: false });
57+
expect(wrapper).toMatchSnapshot();
58+
});
5359
});

src/components/input_fields/input_field_wrapper.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export interface InputFieldProps {
4242
* It should be translated. Can be JSX.Element[] if returned from I18n.interpolateElements
4343
*/
4444
validationError?: string | JSX.Element[];
45+
/** Whether to show the validation error message or not */
46+
showValidationError?: boolean;
4547
}
4648

4749
/**
@@ -80,8 +82,8 @@ export class InputFieldWrapper extends React.Component<InputFieldWrapperProps, {
8082
}
8183

8284
private _showValidationError(): boolean {
83-
const { validationError, submitted, touched } = this.props;
84-
return validationError && (touched || submitted);
85+
const { validationError, submitted, touched, showValidationError } = this.props;
86+
return validationError && (touched || submitted) && showValidationError;
8587
}
8688

8789
private _renderLabel(): JSX.Element {

0 commit comments

Comments
 (0)