Search-as-you-type drop-down should disappear when input focus is lost

Refs #173
This commit is contained in:
Will Abson
2016-06-09 16:17:52 +01:00
parent 914ad910b7
commit 417e0edd44
3 changed files with 36 additions and 14 deletions

View File

@@ -56,6 +56,10 @@ export class AlfrescoSearchControlComponent implements AfterViewInit {
@Input()
autocompleteSearchTerm = '';
searchActive = false;
searchValid = false;
constructor(private translate: AlfrescoTranslationService) {
this.searchControl = new Control(
@@ -63,11 +67,13 @@ export class AlfrescoSearchControlComponent implements AfterViewInit {
Validators.compose([Validators.required, Validators.minLength(3)])
);
this.searchControl.valueChanges.debounceTime(400).distinctUntilChanged().subscribe(
(value: string) => {
this.autocompleteSearchTerm = value;
}
);
this.searchControl.valueChanges.map(value => this.searchControl.valid ? value : '')
.debounceTime(400).distinctUntilChanged().subscribe(
(value: string) => {
this.autocompleteSearchTerm = value;
this.searchValid = this.searchControl.valid;
}
);
translate.addTranslationFolder('node_modules/ng2-alfresco-search');
}
@@ -105,4 +111,18 @@ export class AlfrescoSearchControlComponent implements AfterViewInit {
}
}
onFocus(event) {
if (event) {
event.preventDefault();
}
this.searchActive = true;
}
onBlur(event) {
if (event) {
event.preventDefault();
}
this.searchActive = false;
}
}