question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mat-optgroup and mat-option don't support nested structure

See original GitHub issue

Bug, feature request, or proposal:

mat-optgroup and mat-option don’t support nested structure

What is the expected behavior?

i expect mat-optgroup and mat-option support nested structure

What are the steps to reproduce?

click it open this url and replace template app/select-optgroup-example.htmlwith follow code:

<mat-form-field>
  <mat-select placeholder="Pokemon" [formControl]="pokemonControl">
    <mat-option>-- None --</mat-option>
    <mat-optgroup *ngFor="let group of pokemonGroups" [label]="group.name"
                  [disabled]="group.disabled">
      <mat-option *ngFor="let pokemon of group.pokemon" [value]="pokemon.value">
        {{ pokemon.viewValue }}
      </mat-option>

      <mat-optgroup *ngFor="let group of pokemonGroups" [label]="group.name"
                  [disabled]="group.disabled">
        <mat-option *ngFor="let pokemon of group.pokemon" [value]="pokemon.value">
          {{ pokemon.viewValue }}
        </mat-option>     
      </mat-optgroup>

    </mat-optgroup>
  </mat-select>
</mat-form-field>

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular CLI: 1.5.2
Node: 8.9.1
OS: win32 x64
Angular: 5.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cdk: 5.0.0-rc0
@angular/cli: 1.5.2
@angular/material: 5.0.0-rc0
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@schematics/angular: 0.1.5
typescript: 2.4.2
webpack: 3.8.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
micvolocommented, Aug 30, 2019

hi all, I found a better workaround: just put another mat-select inside the mat-optgroup. Here is my example:

<mat-form-field>
  <mat-select placeholder="YOURPLACEHOLDER" formControlName="YOURFORMCONTROL">

    <div *ngFor="let level1 of YOURDATA">
      <mat-optgroup *ngIf="level1.children else leaf"  [label]="level1.name">
        <mat-select>

          <div *ngFor="let level2 of level1.children">
            <mat-optgroup *ngIf="level2.children else leaf"  [label]="level2.name">
              <mat-select>

                <mat-option *ngFor="let level3 of level2.children" [value]="level3.type">{{level1.name + ' ' + level2.name + ' ' + level3.name}}</mat-option>

              </mat-select>
            </mat-optgroup>
            <ng-template #leaf>
              <mat-option [value]="level2.type">{{level1.name + ' ' + level2.name}}</mat-option>
            </ng-template>
          </div>

        </mat-select>
      </mat-optgroup>
      <ng-template #leaf>
        <mat-option [value]="level1.type">{{level1.name}}</mat-option>
      </ng-template>
    </div>
    
  </mat-select>
</mat-form-field>
3reactions
fgouguenheimcommented, Jun 5, 2019

Hello. This feature would be appreciated. Is it planned to be implemented ? Is there any workaround otherwise ? Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular MatOptGroup Autocomplete with nested JSON structure
I solved it. export const _filterChildren = (opt: Database[], value: string): Database[] => { const filterValue = value.
Read more >
<optgroup>: The Option Group element - MDN Web Docs
The <optgroup> HTML element creates a grouping of options within a <select> element. ... Note: Optgroup elements may not be nested.
Read more >
How To Customize Mat Select Option Group To Allow Nested ...
The <mat-optgroup> element can be used to group common options under a subheading. but can be configured to allow multiple selection by setting...
Read more >
Create a Nested Multi-select Tree with in Angular
Part 1: Introducing the MatTree. Traditional SELECT elements have long allowed multiple selections via the multiple attribute. The means for ...
Read more >
grouped select/options from nested data
You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found