@@ -123,6 +123,7 @@ describe('MatSelect', () => {
123
123
BasicSelect ,
124
124
MultiSelect ,
125
125
SelectWithGroups ,
126
+ SelectWithGroupsAndNgContainer ,
126
127
] ) ;
127
128
} ) ) ;
128
129
@@ -991,6 +992,19 @@ describe('MatSelect', () => {
991
992
992
993
expect ( option . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
993
994
} ) ) ;
995
+
996
+ it ( 'should be able to render options inside groups with an ng-container' , fakeAsync ( ( ) => {
997
+ fixture . destroy ( ) ;
998
+
999
+ const groupFixture = TestBed . createComponent ( SelectWithGroupsAndNgContainer ) ;
1000
+ groupFixture . detectChanges ( ) ;
1001
+ trigger = groupFixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement ;
1002
+ trigger . click ( ) ;
1003
+ groupFixture . detectChanges ( ) ;
1004
+
1005
+ expect ( document . querySelectorAll ( '.cdk-overlay-container mat-option' ) . length )
1006
+ . toBeGreaterThan ( 0 , 'Expected at least one option to be rendered.' ) ;
1007
+ } ) ) ;
994
1008
} ) ;
995
1009
996
1010
describe ( 'selection logic' , ( ) => {
@@ -4200,6 +4214,30 @@ class SelectWithGroups {
4200
4214
@ViewChildren ( MatOption ) options : QueryList < MatOption > ;
4201
4215
}
4202
4216
4217
+ @Component ( {
4218
+ selector : 'select-with-groups' ,
4219
+ template : `
4220
+ <mat-form-field>
4221
+ <mat-select placeholder="Pokemon" [formControl]="control">
4222
+ <mat-optgroup *ngFor="let group of pokemonTypes" [label]="group.name">
4223
+ <ng-container *ngFor="let pokemon of group.pokemon">
4224
+ <mat-option [value]="pokemon.value">{{ pokemon.viewValue }}</mat-option>
4225
+ </ng-container>
4226
+ </mat-optgroup>
4227
+ </mat-select>
4228
+ </mat-form-field>
4229
+ `
4230
+ } )
4231
+ class SelectWithGroupsAndNgContainer {
4232
+ control = new FormControl ( ) ;
4233
+ pokemonTypes = [
4234
+ {
4235
+ name : 'Grass' ,
4236
+ pokemon : [ { value : 'bulbasaur-0' , viewValue : 'Bulbasaur' } ]
4237
+ }
4238
+ ] ;
4239
+ }
4240
+
4203
4241
@Component ( {
4204
4242
template : `
4205
4243
<form>
0 commit comments