Skip to content

fix(select): options inside option group not being rendered when wrapped with ng-container #9769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/core/option/optgroup.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<label class="mat-optgroup-label" [id]="_labelId">{{ label }}</label>
<ng-content select="mat-option"></ng-content>
<ng-content select="mat-option, ng-container"></ng-content>
38 changes: 38 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('MatSelect', () => {
BasicSelect,
MultiSelect,
SelectWithGroups,
SelectWithGroupsAndNgContainer,
]);
}));

Expand Down Expand Up @@ -991,6 +992,19 @@ describe('MatSelect', () => {

expect(option.querySelectorAll('.mat-ripple-element').length).toBe(0);
}));

it('should be able to render options inside groups with an ng-container', fakeAsync(() => {
fixture.destroy();

const groupFixture = TestBed.createComponent(SelectWithGroupsAndNgContainer);
groupFixture.detectChanges();
trigger = groupFixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
trigger.click();
groupFixture.detectChanges();

expect(document.querySelectorAll('.cdk-overlay-container mat-option').length)
.toBeGreaterThan(0, 'Expected at least one option to be rendered.');
}));
});

describe('selection logic', () => {
Expand Down Expand Up @@ -4200,6 +4214,30 @@ class SelectWithGroups {
@ViewChildren(MatOption) options: QueryList<MatOption>;
}

@Component({
selector: 'select-with-groups',
template: `
<mat-form-field>
<mat-select placeholder="Pokemon" [formControl]="control">
<mat-optgroup *ngFor="let group of pokemonTypes" [label]="group.name">
<ng-container *ngFor="let pokemon of group.pokemon">
<mat-option [value]="pokemon.value">{{ pokemon.viewValue }}</mat-option>
</ng-container>
</mat-optgroup>
</mat-select>
</mat-form-field>
`
})
class SelectWithGroupsAndNgContainer {
control = new FormControl();
pokemonTypes = [
{
name: 'Grass',
pokemon: [{ value: 'bulbasaur-0', viewValue: 'Bulbasaur' }]
}
];
}

@Component({
template: `
<form>
Expand Down