This repository has been archived by the owner on Oct 1, 2022. It is now read-only.
forked from ng-bootstrap/ng-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…oses ng-bootstrap#1853
- Loading branch information
Showing
6 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
demo/src/app/components/typeahead/demos/focus/typeahead-focus.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,14 @@ | ||
It is possible to get the focus events with the current input value to emit results on focus with a great flexibility. | ||
|
||
In this simple example, a search is done no matter the content of the input: | ||
|
||
<ul> | ||
<li>on empty input all options will be taken</li> | ||
<li>otherwise options will be filtered against the search term</li> | ||
<li>it will limit the display to 10 results in all cases</li> | ||
</ul> | ||
|
||
<label for="typeahead-focus">Search for a state:</label> | ||
<input id="typeahead-focus" type="text" class="form-control" [(ngModel)]="model" [ngbTypeahead]="search"/> | ||
<hr> | ||
<pre>Model: {{ model | json }}</pre> |
31 changes: 31 additions & 0 deletions
31
demo/src/app/components/typeahead/demos/focus/typeahead-focus.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 {Observable} from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/map'; | ||
import 'rxjs/add/operator/debounceTime'; | ||
import 'rxjs/add/operator/distinctUntilChanged'; | ||
|
||
const states = ['Alabama', 'Alaska', 'American Samoa', 'Arizona', 'Arkansas', 'California', 'Colorado', | ||
'Connecticut', 'Delaware', 'District Of Columbia', 'Federated States Of Micronesia', 'Florida', 'Georgia', | ||
'Guam', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', | ||
'Marshall Islands', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', | ||
'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', | ||
'Northern Mariana Islands', 'Ohio', 'Oklahoma', 'Oregon', 'Palau', 'Pennsylvania', 'Puerto Rico', 'Rhode Island', | ||
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virgin Islands', 'Virginia', | ||
'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']; | ||
|
||
@Component({ | ||
selector: 'ngbd-typeahead-focus', | ||
templateUrl: './typeahead-focus.html', | ||
styles: [`.form-control { width: 300px; }`] | ||
}) | ||
export class NgbdTypeaheadFocus { | ||
public model: any; | ||
|
||
search = (text$: Observable<string>, focus$: Observable<string>) => | ||
text$ | ||
.debounceTime(200) | ||
.distinctUntilChanged() | ||
.merge(focus$) | ||
.map(term => (term === '' ? states : states.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1)).slice(0, 10)); | ||
|
||
} |
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
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
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
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