@@ -123,6 +123,7 @@ describe('MatSelect', () => {
123123 BasicSelect ,
124124 MultiSelect ,
125125 SelectWithGroups ,
126+ SelectWithGroupsAndNgContainer ,
126127 ] ) ;
127128 } ) ) ;
128129
@@ -991,6 +992,19 @@ describe('MatSelect', () => {
991992
992993 expect ( option . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
993994 } ) ) ;
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+ } ) ) ;
9941008 } ) ;
9951009
9961010 describe ( 'selection logic' , ( ) => {
@@ -4200,6 +4214,30 @@ class SelectWithGroups {
42004214 @ViewChildren ( MatOption ) options : QueryList < MatOption > ;
42014215}
42024216
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+
42034241@Component ( {
42044242 template : `
42054243 <form>
0 commit comments