mirror of
https://github.com/NicolasConstant/sengi
synced 2025-02-01 19:16:52 +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[] = [];
|
hashtags: string[] = [];
|
||||||
|
|
||||||
@Output() suggestionSelectedEvent = new EventEmitter<AutosuggestSelection>();
|
@Output() suggestionSelectedEvent = new EventEmitter<AutosuggestSelection>();
|
||||||
|
@Output() hasSuggestionsEvent = new EventEmitter<boolean>();
|
||||||
|
|
||||||
private _pattern: string;
|
private _pattern: string;
|
||||||
@Input('pattern')
|
@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 => {
|
.catch(err => {
|
||||||
this.notificationService.notifyHttpError(err);
|
this.notificationService.notifyHttpError(err);
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
<app-autosuggest class="status-form__autosuggest" *ngIf="autosuggestData"
|
<app-autosuggest class="status-form__autosuggest" *ngIf="autosuggestData"
|
||||||
[pattern]="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>
|
<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 {
|
handleKeyDown(event: KeyboardEvent): boolean {
|
||||||
if(this.autosuggestData){
|
if(this.hasSuggestions){
|
||||||
if (event.keyCode === DOWN_ARROW || event.keyCode === UP_ARROW || event.keyCode === ENTER) {
|
if (event.keyCode === DOWN_ARROW || event.keyCode === UP_ARROW || event.keyCode === ENTER) {
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user