Skip to content

Commit 3381f26

Browse files
authored
fix: make border configurable in form field (#1311)
1 parent 9df5db8 commit 3381f26

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

projects/components/src/form-field/form-field.component.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
.content {
3333
flex: 1 1 auto;
3434
width: 100%;
35-
border: 1px solid $gray-2;
36-
border-radius: 6px;
37-
width: 100%;
3835
background: white;
3936

37+
&.show-border {
38+
border: 1px solid $gray-2;
39+
border-radius: 6px;
40+
}
41+
4042
&.error-border {
4143
border: 1px solid $red-3;
4244
}

projects/components/src/form-field/form-field.component.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ describe('Form Field Component', () => {
2828
}
2929
}
3030
);
31+
32+
expect(spectator.query('.content')).not.toHaveClass(['show-border', 'error-border']);
33+
expect(spectator.query('.content')).toExist();
34+
3135
const labels = spectator.queryAll(LabelComponent);
3236
expect(labels[0].label).toEqual('Label');
3337
expect(labels[1].label).toEqual('Error message');
@@ -55,19 +59,21 @@ describe('Form Field Component', () => {
5559
expect(labels[1].label).toEqual('(Optional)');
5660
});
5761

58-
test('should show error when showFormError and errorLabel is present', () => {
62+
test('should show error when showFormError, errorLabel and showBorder is present', () => {
5963
const spectator = hostFactory(
6064
`
61-
<ht-form-field [label]="label" [showFormError]="showFormError" [errorLabel]="errorLabel">
65+
<ht-form-field [label]="label" [showFormError]="showFormError" [errorLabel]="errorLabel" [showBorder]="showBorder">
6266
</ht-form-field>`,
6367
{
6468
hostProps: {
6569
label: 'Label',
6670
errorLabel: 'Invalid Form element',
67-
showFormError: true
71+
showFormError: true,
72+
showBorder: true
6873
}
6974
}
7075
);
76+
expect(spectator.query('.content')).toHaveClass(['content', 'show-border', 'error-border']);
7177

7278
expect(spectator.query('.error')).toExist();
7379

@@ -81,5 +87,6 @@ describe('Form Field Component', () => {
8187
});
8288

8389
expect(spectator.query('.error')).not.toExist();
90+
expect(spectator.query('.content')).toHaveClass(['show-border']);
8491
});
8592
});

projects/components/src/form-field/form-field.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ import { IconSize } from '../icon/icon-size';
1919
[htTooltip]="this.iconTooltip"
2020
></ht-icon>
2121
</div>
22-
<div class="content" [ngClass]="{ 'error-border': this.showFormError && this.errorLabel }">
22+
<div
23+
class="content"
24+
[ngClass]="{
25+
'show-border': this.showBorder,
26+
'error-border': this.showFormError && this.errorLabel
27+
}"
28+
>
2329
<ng-content></ng-content>
2430
</div>
2531
<!-- For Backward Compatibility: Start -->
@@ -56,6 +62,9 @@ export class FormFieldComponent {
5662
@Input()
5763
public errorLabel?: string = '';
5864

65+
@Input()
66+
public showBorder: boolean = false;
67+
5968
@Input()
6069
public showFormError?: boolean = true;
6170
}

0 commit comments

Comments
 (0)