forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(autocomplete): add docs and example for autoActiveFirstOption (a…
…ngular#9735) Adds some documentation and a live example for the `MatAutocomplete.autoActiveFirstOption` property.
- Loading branch information
1 parent
4523ecd
commit 28dbbd5
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...s/autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.example-form { | ||
min-width: 150px; | ||
max-width: 500px; | ||
width: 100%; | ||
} | ||
|
||
.example-full-width { | ||
width: 100%; | ||
} |
10 changes: 10 additions & 0 deletions
10
.../autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<form class="example-form"> | ||
<mat-form-field class="example-full-width"> | ||
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto"> | ||
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete"> | ||
<mat-option *ngFor="let option of filteredOptions | async" [value]="option"> | ||
{{ option }} | ||
</mat-option> | ||
</mat-autocomplete> | ||
</mat-form-field> | ||
</form> |
31 changes: 31 additions & 0 deletions
31
...es/autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import {startWith} from 'rxjs/operators/startWith'; | ||
import {map} from 'rxjs/operators/map'; | ||
|
||
/** | ||
* @title Highlight the first autocomplete option | ||
*/ | ||
@Component({ | ||
selector: 'autocomplete-auto-active-first-option-example', | ||
templateUrl: 'autocomplete-auto-active-first-option-example.html', | ||
styleUrls: ['autocomplete-auto-active-first-option-example.css'] | ||
}) | ||
export class AutocompleteAutoActiveFirstOptionExample { | ||
myControl: FormControl = new FormControl(); | ||
options = ['One', 'Two', 'Three']; | ||
filteredOptions: Observable<string[]>; | ||
|
||
ngOnInit() { | ||
this.filteredOptions = this.myControl.valueChanges.pipe( | ||
startWith(''), | ||
map(val => this.filter(val)) | ||
); | ||
} | ||
|
||
filter(val: string): string[] { | ||
return this.options.filter(option => option.toLowerCase().indexOf(val.toLowerCase()) === 0); | ||
} | ||
|
||
} |