-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(autocomplete): Adds option group example #10666
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
docs(autocomplete): Adds option group example #10666
Conversation
Adds a option group example which displays ideal logic and best practices for the material autocomplete component.
</mat-optgroup> | ||
</mat-autocomplete> | ||
</mat-form-field> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary closing tag.
@@ -0,0 +1,13 @@ | |||
<form [formGroup]="animalForm" novalidate> | |||
<mat-form-field> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation seems to be wrong here.
<input type="text" matInput placeholder="Species Group" formControlName="speciesGroup" required [matAutocomplete]="autoGroup"/> | ||
<mat-autocomplete #autoGroup="matAutocomplete"> | ||
<mat-optgroup *ngFor="let group of speciesGroupeOptions | async" [label]="group.letter"> | ||
<mat-option *ngFor="let name of group.name" [value]="name"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space before the value
binding.
</mat-autocomplete> | ||
</mat-form-field> | ||
</div> | ||
</form> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs an extra line at the end of the file.
@@ -0,0 +1,63 @@ | |||
import { Component, OnInit } from '@angular/core'; | |||
import { FormGroup, FormBuilder, Validators } from '@angular/forms'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing around the imports is inconsistent.
class SpeciesGroup { | ||
letter:string; | ||
name: string[]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a newline at the end of the file.
} | ||
|
||
class SpeciesGroup { | ||
letter:string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space after letter:
.
|
||
class SpeciesGroup { | ||
letter:string; | ||
name: string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an array it should be called names
.
|
||
buildForm() { | ||
this.animalForm = this.fb.group({ | ||
species: ['', [Validators.required]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that we should start putting validation on this. We try to keep the examples as simple as possible and in this case the validation doesn't add anything.
filterGroup(val: string): SpeciesGroup[] { | ||
if (val) { | ||
return this.speciesGroup | ||
.map(group => ({ letter: group.letter, name: this._filter(group.name, val) })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The map
and the filter
need some indentation.
import { Component, OnInit } from '@angular/core'; | ||
import { FormGroup, FormBuilder, Validators } from '@angular/forms'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { startWith } from 'rxjs/operators/startWith'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we don't do spaces around the imports. E.g. these should be import {startWith} from 'rxjs/operators/startWith';
|
||
ngOnInit() { | ||
this.stateGroupOptions = this.stateForm.get('stateGroup').valueChanges | ||
.pipe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .pipe
should either be on the previous line or be indented.
stateGroupOptions: Observable<StateGroup[]>; | ||
|
||
constructor(private fb: FormBuilder) { | ||
this.stateForm = this.fb.group({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can initialize this one when you declare the property.
names: ['Vermont', 'Virginia'] | ||
}, { | ||
letter: 'W', | ||
names: ['Washingto n', 'West Virginia', 'Wisconsin', 'Wyoming'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space before the "n".
84b5503
to
fcb8824
Compare
Thanks for the reviews @crisbeto, I do apologize for the little items such as the spacing which really I should be catching as well. Will make note to improve and be diligent about that. |
Just noticed the lint and e2e failures, will address today. |
fcb8824
to
337fcbc
Compare
Sorry for the delay, I've been wrestling school obligations and apartment hunting prior to starting a new job. Does anyone have any idea how to fix the lint error here? I have not seen it before:
Here is the code that I'm trying to use: stateForm: FormGroup = this.fb.group({
stateGroup: '',
}); |
Just remove |
337fcbc
to
e046c28
Compare
@@ -0,0 +1,12 @@ | |||
<form [formGroup]="stateForm" novalidate> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
novalidate
isn't necessary.
e046c28
to
1589821
Compare
} | ||
} | ||
|
||
class StateGroup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could replace this by an Interface
and move this to the top of the file (after imports);
32976e5
to
76a8680
Compare
Changes code style and logic to expected logic and styleguide
76a8680
to
23f7333
Compare
Thanks for the tips @rafaelss95, and sorry for the delay. I've fixed the Lint / E2E issues, and the failing test case relates to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
fixes #10196,
StackBlitz example: https://stackblitz.com/edit/angular-smg2xm?file=app/app.component.ts
Adds a option group example which displays ideal logic and best practices for the material autocomplete component when using said groups.