intercept event only when there is suggestions

This commit is contained in:
Nicolas Constant 2019-07-23 00:57:50 -04:00
parent 6d4beceb32
commit 0ced6445b5
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 16 additions and 2 deletions

View File

@ -15,6 +15,7 @@ export class AutosuggestComponent implements OnInit {
hashtags: string[] = [];
@Output() suggestionSelectedEvent = new EventEmitter<AutosuggestSelection>();
@Output() hasSuggestionsEvent = new EventEmitter<boolean>();
private _pattern: string;
@Input('pattern')
@ -70,6 +71,13 @@ export class AutosuggestComponent implements OnInit {
}
}
})
.then(() => {
if(this.hashtags.length > 0 || this.accounts.length > 0){
this.hasSuggestionsEvent.next(true);
} else {
this.hasSuggestionsEvent.next(false);
}
})
.catch(err => {
this.notificationService.notifyHttpError(err);
});

View File

@ -14,7 +14,8 @@
<app-autosuggest class="status-form__autosuggest" *ngIf="autosuggestData"
[pattern]="autosuggestData"
(suggestionSelectedEvent)="suggestionSelected($event)"></app-autosuggest>
(suggestionSelectedEvent)="suggestionSelected($event)"
(hasSuggestionsEvent)="suggestionsChanged($event)"></app-autosuggest>
<div class="status-form__mention-error" *ngIf="mentionTooFarAwayError">Error: mentions must be placed closer to the start in order to use multiposting.</div>

View File

@ -475,8 +475,13 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
}
}
private hasSuggestions: boolean;
suggestionsChanged(hasSuggestions: boolean) {
this.hasSuggestions = hasSuggestions;
}
handleKeyDown(event: KeyboardEvent): boolean {
if(this.autosuggestData){
if(this.hasSuggestions){
if (event.keyCode === DOWN_ARROW || event.keyCode === UP_ARROW || event.keyCode === ENTER) {
event.stopImmediatePropagation();
event.preventDefault();