-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typeahead): add
selectOnExact
option
The description from the old docs in angular-ui: typeahead-select-on-exact (Default: false) - Automatically select the item when it is the only one that exactly matches the user input. Fixes #4371
- Loading branch information
1 parent
417314a
commit 4eb6cc7
Showing
8 changed files
with
256 additions
and
18 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
demo/src/app/components/typeahead/demos/select-on-exact/typeahead-select-on-exact.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,6 @@ | ||
A typeahead example that selects the item when it is the only one that matches the user input | ||
|
||
<label for="typeahead-select-on-exact">Search for a state:</label> | ||
<input id="typeahead-select-on-exact" type="text" class="form-control" [(ngModel)]="model" [ngbTypeahead]="search" /> | ||
<hr /> | ||
<pre>Model: {{ model | json }}</pre> |
13 changes: 13 additions & 0 deletions
13
demo/src/app/components/typeahead/demos/select-on-exact/typeahead-select-on-exact.module.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,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgbdTypeaheadSelectOnExact } from './typeahead-select-on-exact'; | ||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@NgModule({ | ||
imports: [BrowserModule, FormsModule, NgbModule], | ||
declarations: [NgbdTypeaheadSelectOnExact], | ||
exports: [NgbdTypeaheadSelectOnExact], | ||
bootstrap: [NgbdTypeaheadSelectOnExact], | ||
}) | ||
export class NgbdTypeaheadSelectOnExactModule {} |
89 changes: 89 additions & 0 deletions
89
demo/src/app/components/typeahead/demos/select-on-exact/typeahead-select-on-exact.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,89 @@ | ||
import { Component } from '@angular/core'; | ||
import { Observable, OperatorFunction } from 'rxjs'; | ||
import { debounceTime, distinctUntilChanged, map } from 'rxjs/operators'; | ||
|
||
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-select-on-exact', | ||
templateUrl: './typeahead-select-on-exact.html', | ||
styles: [ | ||
` | ||
.form-control { | ||
width: 300px; | ||
} | ||
`, | ||
], | ||
}) | ||
export class NgbdTypeaheadSelectOnExact { | ||
public model: any; | ||
|
||
search: OperatorFunction<string, readonly string[]> = (text$: Observable<string>) => | ||
text$.pipe( | ||
debounceTime(200), | ||
distinctUntilChanged(), | ||
map((term) => | ||
term.length < 2 ? [] : 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
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