@@ -458,6 +458,27 @@ describe('MatInput without forms', () => {
458458 expect ( inputEl . disabled ) . toBe ( true ) ;
459459 } ) ;
460460
461+ it ( 'should update the disabled styling when the form field control is swapped out' , ( ) => {
462+ const fixture = TestBed . createComponent ( MatInputWithSwappedControl ) ;
463+ fixture . detectChanges ( ) ;
464+
465+ const wrapperEl = fixture . debugElement . query (
466+ By . css ( '.mat-mdc-text-field-wrapper' ) ,
467+ ) ! . nativeElement ;
468+
469+ expect ( wrapperEl . classList . contains ( 'mdc-text-field--disabled' ) )
470+ . withContext ( `Expected form field not to start out disabled.` )
471+ . toBe ( false ) ;
472+
473+ fixture . componentInstance . disabled = true ;
474+ fixture . changeDetectorRef . markForCheck ( ) ;
475+ fixture . detectChanges ( ) ;
476+
477+ expect ( wrapperEl . classList . contains ( 'mdc-text-field--disabled' ) )
478+ . withContext ( `Expected form field to look disabled after the control was swapped.` )
479+ . toBe ( true ) ;
480+ } ) ;
481+
461482 it ( 'should be able to set an input as being disabled and interactive' , ( ) => {
462483 const fixture = TestBed . createComponent ( MatInputWithDisabled ) ;
463484 fixture . componentInstance . disabled = true ;
@@ -1746,6 +1767,23 @@ class MatInputWithDisabled {
17461767 disabledInteractive = false ;
17471768}
17481769
1770+ @Component ( {
1771+ template : `
1772+ <mat-form-field>
1773+ @if (disabled) {
1774+ <input matInput [disabled]="true">
1775+ } @else {
1776+ <input matInput>
1777+ }
1778+ </mat-form-field>
1779+ ` ,
1780+ imports : [ MatInputModule ] ,
1781+ changeDetection : ChangeDetectionStrategy . Eager ,
1782+ } )
1783+ class MatInputWithSwappedControl {
1784+ disabled = false ;
1785+ }
1786+
17491787@Component ( {
17501788 template : `<mat-form-field><input matInput [required]="required"></mat-form-field>` ,
17511789 imports : [ MatInputModule ] ,
0 commit comments