-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(demos): autocomplete examples #5787
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
src/material-examples/autocomplete-display/autocomplete-display-example.css
This file contains hidden or 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,7 @@ | ||
.example-form { | ||
width: 500px; | ||
} | ||
|
||
.example-full-width { | ||
width: 100%; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/material-examples/autocomplete-display/autocomplete-display-example.html
This file contains hidden or 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,11 @@ | ||
<form class="example-form"> | ||
<md-input-container class="example-full-width"> | ||
<input type="text" placeholder="Assignee" aria-label="Assignee" mdInput [formControl]="myControl" [mdAutocomplete]="auto"> | ||
</md-input-container> | ||
|
||
<md-autocomplete #auto="mdAutocomplete" [displayWith]="displayFn"> | ||
<md-option *ngFor="let option of filteredOptions | async" [value]="option"> | ||
{{ option.name }} | ||
</md-option> | ||
</md-autocomplete> | ||
</form> |
47 changes: 47 additions & 0 deletions
47
src/material-examples/autocomplete-display/autocomplete-display-example.ts
This file contains hidden or 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,47 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/startWith'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
export class User { | ||
constructor(public name: string) { } | ||
} | ||
|
||
/** | ||
* @title Display value autocomplete | ||
*/ | ||
@Component({ | ||
selector: 'autocomplete-display-example', | ||
templateUrl: 'autocomplete-display-example.html', | ||
styleUrls: ['autocomplete-display-example.css'] | ||
}) | ||
export class AutocompleteDisplayExample { | ||
|
||
myControl = new FormControl(); | ||
|
||
options = [ | ||
new User('Mary'), | ||
new User('Shelley'), | ||
new User('Igor') | ||
]; | ||
|
||
filteredOptions: Observable<User[]>; | ||
|
||
ngOnInit() { | ||
this.filteredOptions = this.myControl.valueChanges | ||
.startWith(null) | ||
.map(user => user && typeof user === 'object' ? user.name : user) | ||
.map(name => name ? this.filter(name) : this.options.slice()); | ||
} | ||
|
||
filter(name: string): User[] { | ||
return this.options.filter(option => | ||
option.name.toLowerCase().indexOf(name.toLowerCase()) === 0); | ||
} | ||
|
||
displayFn(user: User): string { | ||
return user ? user.name : user; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/material-examples/autocomplete-filter/autocomplete-filter-example.css
This file contains hidden or 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,7 @@ | ||
.example-form { | ||
width: 500px; | ||
} | ||
|
||
.example-full-width { | ||
width: 100%; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/material-examples/autocomplete-filter/autocomplete-filter-example.html
This file contains hidden or 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,11 @@ | ||
<form class="example-form"> | ||
<md-input-container class="example-full-width"> | ||
<input type="text" placeholder="Pick one" aria-label="Number" mdInput [formControl]="myControl" [mdAutocomplete]="auto"> | ||
</md-input-container> | ||
|
||
<md-autocomplete #auto="mdAutocomplete"> | ||
<md-option *ngFor="let option of filteredOptions | async" [value]="option"> | ||
{{ option }} | ||
</md-option> | ||
</md-autocomplete> | ||
</form> |
38 changes: 38 additions & 0 deletions
38
src/material-examples/autocomplete-filter/autocomplete-filter-example.ts
This file contains hidden or 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,38 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/startWith'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
/** | ||
* @title Filter autocomplete | ||
*/ | ||
@Component({ | ||
selector: 'autocomplete-filter-example', | ||
templateUrl: 'autocomplete-filter-example.html', | ||
styleUrls: ['autocomplete-filter-example.css'] | ||
}) | ||
export class AutocompleteFilterExample { | ||
|
||
myControl: FormControl = new FormControl(); | ||
|
||
options = [ | ||
'One', | ||
'Two', | ||
'Three' | ||
]; | ||
|
||
filteredOptions: Observable<string[]>; | ||
|
||
ngOnInit() { | ||
this.filteredOptions = this.myControl.valueChanges | ||
.startWith(null) | ||
.map(val => val ? this.filter(val) : this.options.slice()); | ||
} | ||
|
||
filter(val: string): string[] { | ||
return this.options.filter(option => | ||
option.toLowerCase().indexOf(val.toLowerCase()) === 0); | ||
} | ||
|
||
} |
This file contains hidden or 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,7 @@ | ||
.example-form { | ||
width: 500px; | ||
} | ||
|
||
.example-full-width { | ||
width: 100%; | ||
} |
28 changes: 20 additions & 8 deletions
28
src/material-examples/autocomplete-overview/autocomplete-overview-example.html
This file contains hidden or 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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
<md-input-container> | ||
<input mdInput placeholder="State" [mdAutocomplete]="auto" [formControl]="stateCtrl"> | ||
</md-input-container> | ||
<form class="example-form"> | ||
<md-input-container class="example-full-width"> | ||
<input mdInput placeholder="State" aria-label="State" [mdAutocomplete]="auto" [formControl]="stateCtrl"> | ||
</md-input-container> | ||
|
||
<md-autocomplete #auto="mdAutocomplete"> | ||
<md-option *ngFor="let state of filteredStates | async" [value]="state"> | ||
{{ state }} | ||
</md-option> | ||
</md-autocomplete> | ||
<md-autocomplete #auto="mdAutocomplete"> | ||
<md-option *ngFor="let state of filteredStates | async" [value]="state.name"> | ||
<img style="vertical-align:middle;" aria-hidden src="{{state.flag}}" height="25" /> | ||
<span>{{ state.name }}</span> | | ||
<small>Population: {{state.population}}</small> | ||
</md-option> | ||
</md-autocomplete> | ||
|
||
<br /> | ||
|
||
<md-slide-toggle | ||
[checked]="stateCtrl.disabled" | ||
(change)="stateCtrl.disabled ? stateCtrl.enable() : stateCtrl.disable()"> | ||
Disable Input? | ||
</md-slide-toggle> | ||
</form> |
90 changes: 33 additions & 57 deletions
90
src/material-examples/autocomplete-overview/autocomplete-overview-example.ts
This file contains hidden or 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 |
---|---|---|
@@ -1,83 +1,59 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
|
||
import {Observable} from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/startWith'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
/** | ||
* @title Basic autocomplete | ||
* @title Autocomplete overview | ||
*/ | ||
@Component({ | ||
selector: 'autocomplete-overview-example', | ||
templateUrl: 'autocomplete-overview-example.html', | ||
styleUrls: ['autocomplete-overview-example.css'] | ||
}) | ||
export class AutocompleteOverviewExample { | ||
stateCtrl: FormControl; | ||
filteredStates: any; | ||
filteredStates: Observable<any[]>; | ||
|
||
states = [ | ||
'Alabama', | ||
'Alaska', | ||
'Arizona', | ||
'Arkansas', | ||
'California', | ||
'Colorado', | ||
'Connecticut', | ||
'Delaware', | ||
'Florida', | ||
'Georgia', | ||
'Hawaii', | ||
'Idaho', | ||
'Illinois', | ||
'Indiana', | ||
'Iowa', | ||
'Kansas', | ||
'Kentucky', | ||
'Louisiana', | ||
'Maine', | ||
'Maryland', | ||
'Massachusetts', | ||
'Michigan', | ||
'Minnesota', | ||
'Mississippi', | ||
'Missouri', | ||
'Montana', | ||
'Nebraska', | ||
'Nevada', | ||
'New Hampshire', | ||
'New Jersey', | ||
'New Mexico', | ||
'New York', | ||
'North Carolina', | ||
'North Dakota', | ||
'Ohio', | ||
'Oklahoma', | ||
'Oregon', | ||
'Pennsylvania', | ||
'Rhode Island', | ||
'South Carolina', | ||
'South Dakota', | ||
'Tennessee', | ||
'Texas', | ||
'Utah', | ||
'Vermont', | ||
'Virginia', | ||
'Washington', | ||
'West Virginia', | ||
'Wisconsin', | ||
'Wyoming', | ||
states: any[] = [ | ||
{ | ||
name: 'Arkansas', | ||
population: '2.978M', | ||
// https://commons.wikimedia.org/wiki/File:Flag_of_Arkansas.svg | ||
flag: 'https://upload.wikimedia.org/wikipedia/commons/9/9d/Flag_of_Arkansas.svg' | ||
}, | ||
{ | ||
name: 'California', | ||
population: '39.14M', | ||
// https://commons.wikimedia.org/wiki/File:Flag_of_California.svg | ||
flag: 'https://upload.wikimedia.org/wikipedia/commons/0/01/Flag_of_California.svg' | ||
}, | ||
{ | ||
name: 'Florida', | ||
population: '20.27M', | ||
// https://commons.wikimedia.org/wiki/File:Flag_of_Florida.svg | ||
flag: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Flag_of_Florida.svg' | ||
}, | ||
{ | ||
name: 'Texas', | ||
population: '27.47M', | ||
// https://commons.wikimedia.org/wiki/File:Flag_of_Texas.svg | ||
flag: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Flag_of_Texas.svg' | ||
} | ||
]; | ||
|
||
constructor() { | ||
this.stateCtrl = new FormControl(); | ||
this.filteredStates = this.stateCtrl.valueChanges | ||
.startWith(null) | ||
.map(name => this.filterStates(name)); | ||
.map(state => state ? this.filterStates(state) : this.states.slice()); | ||
} | ||
|
||
filterStates(val: string) { | ||
return val ? this.states.filter(s => s.toLowerCase().indexOf(val.toLowerCase()) === 0) | ||
: this.states; | ||
filterStates(name: string) { | ||
return this.states.filter(state => | ||
state.name.toLowerCase().indexOf(name.toLowerCase()) === 0); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/material-examples/autocomplete-simple/autocomplete-simple-example.css
This file contains hidden or 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,7 @@ | ||
.example-form { | ||
width: 500px; | ||
} | ||
|
||
.example-full-width { | ||
width: 100%; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@amcdnl Think you could add
max-width: 100%
before it merges, here and elsewhere? If not, I'll be happy to in subsequent pr.#5839
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.
@willshowell - I was thinking about going through and removing all these fixed widths since it causes responsive issues. I'd like to do that in a separate PR.