Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions projects/components/form-field/src/dummy-mat-form-field-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,23 @@ export class DummyMatFormFieldControl implements MatFormFieldControl<string>, On

public autofilled?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while at it - do you mind changing the indentation on the demo ?
image

each first line should be less indented.
and overall both blocks should be aligned, currently the 2nd block of css is indented less o.O


public ngControl: NgControl | null = null;

private _value: string | null = null;
private _required = false;
private _disabled = false;
private _valueSubscription: Subscription | null = null;
private _statusSubscription: Subscription | null = null;

constructor(
public ngControl: NgControl | null,
formControl: AbstractControl | null
) {
constructor(ngControl: NgControl | null, formControl: AbstractControl | null) {
this.init(ngControl, formControl);
}

public init(ngControl: NgControl | null, formControl: AbstractControl | null) {
this.ngControl = ngControl;

this._valueSubscription?.unsubscribe();
this._statusSubscription?.unsubscribe();
if (formControl) {
this._valueSubscription = formControl.valueChanges.pipe(startWith(formControl.value)).subscribe((value) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
15 changes: 7 additions & 8 deletions projects/components/form-field/src/form-field.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@
style="width: 100%"
[class.mat-form-field--emulated]="emulated"
[class.mat-form-field--no-underline]="noUnderline"
[floatLabel]="floatLabel"
[floatLabel]="floatLabel()"
[hintLabel]="hintText"
>
@if (_labelChild) {
@if (_labelChild()) {
<mat-label>
<ng-content select="mat-label" />
</mat-label>
}
@if (!_labelChild && calculatedLabel) {
} @else if (calculatedLabel()) {
<mat-label>
<mat-label>{{ calculatedLabel }}</mat-label>
<mat-label>{{ calculatedLabel() }}</mat-label>
</mat-label>
}
@if (_prefixChildren.length) {
@if (_prefixChildren().length) {
<ng-container matPrefix>
<ng-content select="[matPrefix]" />
</ng-container>
}
<ng-content />
@if (_suffixChildren.length) {
@if (_suffixChildren().length) {
<ng-container matSuffix>
<ng-content select="[matSuffix]" />
</ng-container>
}
@if (showHintToggle) {
@if (showHintToggle()) {
<button type="button" mat-icon-button matSuffix (click)="toggleHint($event)">
<mat-icon>info_outline</mat-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ describe('ZvFormField', () => {
component.formControl.markAsTouched();
fixture.detectChanges();

expect(component.formField._ngControl.invalid).toBe(true);
expect(component.formField._matFormField._control.errorState).toBe(true);
expect(component.formField._ngControl().invalid).toBe(true);
expect(component.formField._matFormField()._control.errorState).toBe(true);

let errorsChecked = false;
component.formField.errors$.subscribe((e) => {
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('ZvFormField', () => {
const component = fixture.componentInstance;
expect(component).toBeDefined();

expect(component.formField.floatLabel).toEqual('auto');
expect(component.formField.floatLabel()).toEqual('auto');
}));

it('should priorize MAT_FORM_FIELD_DEFAULT_OPTIONS over its own settings', waitForAsync(() => {
Expand All @@ -368,7 +368,7 @@ describe('ZvFormField', () => {
const fixture = TestBed.createComponent(TestFormComponent);
const component = fixture.componentInstance;
expect(component).toBeDefined();
expect(component.formField.floatLabel).toEqual('always');
expect(component.formField.floatLabel()).toEqual('always');
}));
});

Expand Down
Loading