@@ -32,7 +32,15 @@ import {
3232 ChangeDetectionStrategy ,
3333} from '@angular/core' ;
3434import { ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
35- import { FormControl , FormsModule , NgForm , ReactiveFormsModule , Validators } from '@angular/forms' ;
35+ import {
36+ FormControl ,
37+ FormsModule ,
38+ NgForm ,
39+ ReactiveFormsModule ,
40+ Validators ,
41+ FormGroup ,
42+ FormBuilder ,
43+ } from '@angular/forms' ;
3644import { MatFormFieldModule } from '@angular/material/form-field' ;
3745import { By } from '@angular/platform-browser' ;
3846import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -935,6 +943,23 @@ describe('MatChipList', () => {
935943 . toBeFalsy ( `Expected chip with the old value not to be selected.` ) ;
936944 } ) ;
937945 } ) ;
946+
947+ it ( 'should keep the disabled state in sync if the form group is swapped and ' +
948+ 'disabled at the same time' , fakeAsync ( ( ) => {
949+ fixture = createComponent ( ChipListInsideDynamicFormGroup ) ;
950+ fixture . detectChanges ( ) ;
951+ const instance = fixture . componentInstance ;
952+ const list : MatChipList = instance . chipList ;
953+
954+ expect ( list . disabled ) . toBe ( false ) ;
955+ expect ( list . chips . toArray ( ) . every ( chip => chip . disabled ) ) . toBe ( false ) ;
956+
957+ instance . assignGroup ( true ) ;
958+ fixture . detectChanges ( ) ;
959+
960+ expect ( list . disabled ) . toBe ( true ) ;
961+ expect ( list . chips . toArray ( ) . every ( chip => chip . disabled ) ) . toBe ( true ) ;
962+ } ) ) ;
938963 } ) ;
939964
940965 describe ( 'chip list with chip input' , ( ) => {
@@ -1642,3 +1667,31 @@ class ChipListWithRemove {
16421667class PreselectedChipInsideOnPush {
16431668 control = new FormControl ( 'Pizza' ) ;
16441669}
1670+
1671+
1672+ @Component ( {
1673+ template : `
1674+ <form [formGroup]="form">
1675+ <mat-form-field>
1676+ <mat-chip-list formControlName="control">
1677+ <mat-chip>Pizza</mat-chip>
1678+ <mat-chip>Pasta</mat-chip>
1679+ </mat-chip-list>
1680+ </mat-form-field>
1681+ </form>
1682+ `
1683+ } )
1684+ class ChipListInsideDynamicFormGroup {
1685+ @ViewChild ( MatChipList ) chipList : MatChipList ;
1686+ form : FormGroup ;
1687+
1688+ constructor ( private _formBuilder : FormBuilder ) {
1689+ this . assignGroup ( false ) ;
1690+ }
1691+
1692+ assignGroup ( isDisabled : boolean ) {
1693+ this . form = this . _formBuilder . group ( {
1694+ control : { value : [ ] , disabled : isDisabled }
1695+ } ) ;
1696+ }
1697+ }
0 commit comments