@@ -32,7 +32,15 @@ import {
32
32
ChangeDetectionStrategy ,
33
33
} from '@angular/core' ;
34
34
import { 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' ;
36
44
import { MatFormFieldModule } from '@angular/material/form-field' ;
37
45
import { By } from '@angular/platform-browser' ;
38
46
import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -935,6 +943,23 @@ describe('MatChipList', () => {
935
943
. toBeFalsy ( `Expected chip with the old value not to be selected.` ) ;
936
944
} ) ;
937
945
} ) ;
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
+ } ) ) ;
938
963
} ) ;
939
964
940
965
describe ( 'chip list with chip input' , ( ) => {
@@ -1642,3 +1667,31 @@ class ChipListWithRemove {
1642
1667
class PreselectedChipInsideOnPush {
1643
1668
control = new FormControl ( 'Pizza' ) ;
1644
1669
}
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