mirror of
https://github.com/NicolasConstant/sengi
synced 2025-01-21 13:20:48 +01:00
intercept event only when there is suggestions
This commit is contained in:
parent
6d4beceb32
commit
0ced6445b5
@ -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);
|
||||
});
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user