Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/material/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS = new InjectionToken<MatFormFieldDef

/** Styles that are to be applied to the label elements in the outlined appearance. */
type OutlinedLabelStyles =
| [floatingLabelTransform: string, notchedOutlineWidth: number | null]
| null;
[floatingLabelTransform: string, notchedOutlineWidth: number | null] | null;

/** Default appearance used by the form field. */
const DEFAULT_APPEARANCE: MatFormFieldAppearance = 'fill';
Expand Down Expand Up @@ -401,6 +400,7 @@ export class MatFormField
}

this._previousControl = this._control;
this._changeDetectorRef.markForCheck();
}

// make sure the the control has been initialized.
Expand Down
38 changes: 38 additions & 0 deletions src/material/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,27 @@ describe('MatInput without forms', () => {
expect(inputEl.disabled).toBe(true);
});

it('should update the disabled styling when the form field control is swapped out', () => {
const fixture = TestBed.createComponent(MatInputWithSwappedControl);
fixture.detectChanges();

const wrapperEl = fixture.debugElement.query(
By.css('.mat-mdc-text-field-wrapper'),
)!.nativeElement;

expect(wrapperEl.classList.contains('mdc-text-field--disabled'))
.withContext(`Expected form field not to start out disabled.`)
.toBe(false);

fixture.componentInstance.disabled = true;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

expect(wrapperEl.classList.contains('mdc-text-field--disabled'))
.withContext(`Expected form field to look disabled after the control was swapped.`)
.toBe(true);
});

it('should be able to set an input as being disabled and interactive', () => {
const fixture = TestBed.createComponent(MatInputWithDisabled);
fixture.componentInstance.disabled = true;
Expand Down Expand Up @@ -1746,6 +1767,23 @@ class MatInputWithDisabled {
disabledInteractive = false;
}

@Component({
template: `
<mat-form-field>
@if (disabled) {
<input matInput [disabled]="true">
} @else {
<input matInput>
}
</mat-form-field>
`,
imports: [MatInputModule],
changeDetection: ChangeDetectionStrategy.Eager,
})
class MatInputWithSwappedControl {
disabled = false;
}

@Component({
template: `<mat-form-field><input matInput [required]="required"></mat-form-field>`,
imports: [MatInputModule],
Expand Down