mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Search-as-you-type drop-down should disappear when input focus is lost
Refs #173
This commit is contained in:
parent
914ad910b7
commit
417e0edd44
@ -42,6 +42,9 @@ declare let __moduleName: string;
|
||||
height: 32px;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
:host.active.valid {
|
||||
display: block;
|
||||
}`
|
||||
],
|
||||
templateUrl: './alfresco-search-autocomplete.component.html',
|
||||
@ -57,6 +60,9 @@ export class AlfrescoSearchAutocompleteComponent implements OnChanges {
|
||||
|
||||
errorMessage;
|
||||
|
||||
@Input()
|
||||
ngClass: any;
|
||||
|
||||
route: any[] = [];
|
||||
|
||||
constructor(
|
||||
@ -65,18 +71,13 @@ export class AlfrescoSearchAutocompleteComponent implements OnChanges {
|
||||
private el: ElementRef,
|
||||
private renderer: Renderer
|
||||
) {
|
||||
console.log('Autocomplete constructor');
|
||||
translate.addTranslationFolder('node_modules/ng2-alfresco-search');
|
||||
this.results = null;
|
||||
}
|
||||
|
||||
ngOnChanges(changes) {
|
||||
console.log('Autocomplete changes');
|
||||
if (this.searchTerm.length >= 3) {
|
||||
if (changes.searchTerm) {
|
||||
this.displaySearchResults(this.searchTerm);
|
||||
this.renderer.setElementStyle(this.el.nativeElement, 'display', 'block');
|
||||
} else {
|
||||
this.renderer.setElementStyle(this.el.nativeElement, 'display', 'none');
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +86,7 @@ export class AlfrescoSearchAutocompleteComponent implements OnChanges {
|
||||
* @param searchTerm Search query entered by user
|
||||
*/
|
||||
displaySearchResults(searchTerm) {
|
||||
if (searchTerm !== null) {
|
||||
if (searchTerm !== null && searchTerm !== '') {
|
||||
this._alfrescoService
|
||||
.getLiveSearchResults(searchTerm)
|
||||
.subscribe(
|
||||
|
@ -4,9 +4,10 @@
|
||||
<i class="material-icons">search</i>
|
||||
</label>
|
||||
<div [class]="getTextFieldHolderClassName()">
|
||||
<input class="mdl-textfield__input" [type]="inputType" [autocomplete]="getAutoComplete()" id="searchControl" [ngFormControl]="searchControl" [(ngModel)]="searchTerm">
|
||||
<input class="mdl-textfield__input" [type]="inputType" [autocomplete]="getAutoComplete()"
|
||||
id="searchControl" [ngFormControl]="searchControl" [(ngModel)]="searchTerm" (focus)="onFocus()" (blur)="onBlur()">
|
||||
<label class="mdl-textfield__label" for="searchControl">{{'SEARCH.CONTROL.LABEL' | translate}}</label>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<alfresco-search-autocomplete [searchTerm]="autocompleteSearchTerm"></alfresco-search-autocomplete>
|
||||
<alfresco-search-autocomplete [searchTerm]="autocompleteSearchTerm" [ngClass]="{active: searchActive, valid: searchValid}"></alfresco-search-autocomplete>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user