Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 022046a

Browse filesBrowse files
committed
refactor(form-feedback): signal inputs, host bindings, cleanup
1 parent b9943fb commit 022046a
Copy full SHA for 022046a

File tree

Expand file treeCollapse file tree

2 files changed

+22
-17
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-17
lines changed

‎projects/coreui-angular/src/lib/form/form-feedback/form-feedback.component.spec.ts

Copy file name to clipboardExpand all lines: projects/coreui-angular/src/lib/form/form-feedback/form-feedback.component.spec.ts
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
22

33
import { FormFeedbackComponent } from './form-feedback.component';
4+
import { ComponentRef } from '@angular/core';
45

56
describe('FormFeedbackComponent', () => {
67
let component: FormFeedbackComponent;
78
let fixture: ComponentFixture<FormFeedbackComponent>;
9+
let componentRef: ComponentRef<FormFeedbackComponent>;
810

911
beforeEach(waitForAsync(() => {
1012
TestBed.configureTestingModule({
1113
imports: [FormFeedbackComponent]
12-
})
13-
.compileComponents();
14+
}).compileComponents();
1415
}));
1516

1617
beforeEach(() => {
1718
fixture = TestBed.createComponent(FormFeedbackComponent);
1819
component = fixture.componentInstance;
20+
componentRef = fixture.componentRef;
1921
fixture.detectChanges();
2022
});
2123

@@ -24,10 +26,10 @@ describe('FormFeedbackComponent', () => {
2426
});
2527

2628
it('should have css classes', () => {
27-
component.valid = true;
29+
componentRef.setInput('valid', true);
2830
fixture.detectChanges();
2931
expect(fixture.nativeElement).toHaveClass('valid-feedback');
30-
component.valid = false;
32+
componentRef.setInput('valid', false);
3133
fixture.detectChanges();
3234
expect(fixture.nativeElement).toHaveClass('invalid-feedback');
3335
});
+16-13Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
import { booleanAttribute, Component, HostBinding, Input } from '@angular/core';
1+
import { booleanAttribute, Component, computed, input } from '@angular/core';
22

33
@Component({
44
selector: 'c-form-feedback',
5-
template: '<ng-content />'
5+
template: '<ng-content />',
6+
host: { '[class]': 'hostClasses()' }
67
})
78
export class FormFeedbackComponent {
89
/**
910
* If your form layout allows it, you can display validation feedback in a styled tooltip.
10-
* @type boolean
11+
* @default false
1112
*/
12-
@Input({ transform: booleanAttribute }) tooltip: string | boolean = false;
13+
readonly tooltip = input(false, { transform: booleanAttribute });
1314

1415
/**
1516
* Set component validation state to valid.
16-
* @type boolean
17+
* @default undefined
1718
*/
18-
@Input() valid?: boolean;
19+
readonly valid = input<boolean>();
1920

20-
@HostBinding('class')
21-
get hostClasses(): any {
21+
readonly hostClasses = computed(() => {
22+
const status = this.valid() === true ? 'valid' : 'invalid';
23+
const type = this.tooltip() ? 'tooltip' : 'feedback';
2224
return {
23-
'valid-feedback': this.valid === true && !this.tooltip,
24-
'valid-tooltip': this.valid === true && this.tooltip,
25-
'invalid-feedback': this.valid !== true && !this.tooltip,
26-
'invalid-tooltip': this.valid !== true && this.tooltip
25+
[`${status}-${type}`]: true
26+
// 'valid-feedback': valid === true && !tooltip,
27+
// 'valid-tooltip': valid === true && tooltip,
28+
// 'invalid-feedback': valid !== true && !tooltip,
29+
// 'invalid-tooltip': valid !== true && tooltip
2730
};
28-
}
31+
});
2932
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.