Skip to content
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

Typeahead MinLength=0 #412

Merged
merged 4 commits into from
Apr 21, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions components/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Typeahead implements OnInit {
@Output() public typeaheadOnSelect:EventEmitter<{item:any}> = new EventEmitter(false);

@Input() public typeahead:any;
@Input() public typeaheadMinLength:number;
@Input() public typeaheadMinLength:number = void 0;
@Input() public typeaheadWaitMs:number;
@Input() public typeaheadOptionsLimit:number;
@Input() public typeaheadOptionField:string;
Expand Down Expand Up @@ -100,6 +100,22 @@ export class Typeahead implements OnInit {
}
}

@HostListener('focus', ['$event.target'])
protected onFocus():void {
if (this.typeaheadMinLength === 0) {
this.typeaheadLoading.emit(true);

if (this.typeaheadAsync === true) {
this.debouncer();
}

if (this.typeaheadAsync === false) {

This comment was marked as off-topic.

this.processMatches();
this.finalizeAsyncCall();
}
}
}

@HostListener('blur', ['$event.target'])
protected onBlur():void {
// Allow typeahead container click event to be triggered requires a timeout
Expand All @@ -124,7 +140,7 @@ export class Typeahead implements OnInit {

public ngOnInit():void {
this.typeaheadOptionsLimit = this.typeaheadOptionsLimit || 20;
this.typeaheadMinLength = this.typeaheadMinLength || 1;
this.typeaheadMinLength = this.typeaheadMinLength === void 0 ? 1 : this.typeaheadMinLength;
this.typeaheadWaitMs = this.typeaheadWaitMs || 0;

// async should be false in case of array
Expand Down Expand Up @@ -266,6 +282,13 @@ export class Typeahead implements OnInit {
return;
}

if (!this.cd.model) {
for (let i = 0; i < this.typeahead.length; i++) {

This comment was marked as off-topic.

this._matches.push(this.typeahead[i]);
}
return;
}

// If singleWords, break model here to not be doing extra work on each
// iteration
let normalizedQuery = (this.typeaheadLatinize
Expand Down Expand Up @@ -327,7 +350,7 @@ export class Typeahead implements OnInit {
this.typeaheadNoResults.emit(this.cd.model.toString().length >=
this.typeaheadMinLength && this.matches.length <= 0);

if (this.cd.model.toString().length <= 0 || this._matches.length <= 0) {
if (this._matches.length <= 0) {
this.hide();
return;
}
Expand Down