@@ -41,6 +41,7 @@ describe('MatChipList', () => {
41
41
InputChipList ,
42
42
MultiSelectionChipList ,
43
43
FalsyValueChipList ,
44
+ SelectedChipList
44
45
] ,
45
46
providers : [ {
46
47
provide : Directionality , useFactory : ( ) => {
@@ -63,6 +64,21 @@ describe('MatChipList', () => {
63
64
} ) ;
64
65
} ) ;
65
66
67
+ describe ( 'with selected chips' , ( ) => {
68
+ beforeEach ( async ( ( ) => {
69
+ fixture = TestBed . createComponent ( SelectedChipList ) ;
70
+ fixture . detectChanges ( ) ;
71
+ } ) ) ;
72
+
73
+ it ( 'should not override chips selected' , ( ) => {
74
+ const instanceChips = fixture . componentInstance . chips . toArray ( ) ;
75
+
76
+ expect ( instanceChips [ 0 ] . selected ) . toBe ( true , 'Expected first option to be selected.' ) ;
77
+ expect ( instanceChips [ 1 ] . selected ) . toBe ( false , 'Expected second option to be not selected.' ) ;
78
+ expect ( instanceChips [ 2 ] . selected ) . toBe ( true , 'Expected third option to be selected.' ) ;
79
+ } ) ;
80
+ } ) ;
81
+
66
82
describe ( 'focus behaviors' , ( ) => {
67
83
beforeEach ( async ( ( ) => {
68
84
setupStandardList ( ) ;
@@ -1027,3 +1043,21 @@ class FalsyValueChipList {
1027
1043
control = new FormControl ( ) ;
1028
1044
@ViewChildren ( MatChip ) chips : QueryList < MatChip > ;
1029
1045
}
1046
+
1047
+ @Component ( {
1048
+ template : `
1049
+ <mat-chip-list>
1050
+ <mat-chip *ngFor="let food of foods" [value]="food.value" [selected]="food.selected">
1051
+ {{ food.viewValue }}
1052
+ </mat-chip>
1053
+ </mat-chip-list>
1054
+ `
1055
+ } )
1056
+ class SelectedChipList {
1057
+ foods : any [ ] = [
1058
+ { value : 0 , viewValue : 'Steak' , selected : true } ,
1059
+ { value : 1 , viewValue : 'Pizza' , selected : false } ,
1060
+ { value : 2 , viewValue : 'Pasta' , selected : true } ,
1061
+ ] ;
1062
+ @ViewChildren ( MdChip ) chips : QueryList < MdChip > ;
1063
+ }
0 commit comments