CHange keydown listeners to specific key listener to optimize perfomance
This commit is contained in:
parent
0384fe87b9
commit
7e9db1d0de
|
@ -14,7 +14,8 @@ import {EntitiesSelectionComponent} from "../../searchPages/searchUtils/entities
|
|||
@Component({
|
||||
selector: 'advanced-search-input',
|
||||
template: `
|
||||
<div *ngIf="inputs.length > 0" class="search-input" [class.dark]="dark" [ngClass]="searchInputClass" [class.small-vertical]="smallVertical">
|
||||
<div *ngIf="inputs.length > 0" class="search-input" [class.dark]="dark" [ngClass]="searchInputClass"
|
||||
[class.small-vertical]="smallVertical">
|
||||
<div class="uk-flex uk-flex-middle">
|
||||
<div class="uk-width-expand">
|
||||
<div class="uk-grid uk-grid-collapse inputs" [ngClass]="'uk-child-width-1-' + length" uk-grid>
|
||||
|
@ -39,14 +40,13 @@ export class AdvancedSearchInputComponent implements AfterContentInit, OnDestroy
|
|||
@Input() smallVertical: boolean = false;
|
||||
@Output() searchEmitter: EventEmitter<void> = new EventEmitter<void>();
|
||||
|
||||
@HostListener('window:keydown', ['$event'])
|
||||
keyEvent(event: KeyboardEvent) {
|
||||
@HostListener('window:keydown.enter', ['$event'])
|
||||
enter(event: KeyboardEvent) {
|
||||
let input: InputComponent | EntitiesSelectionComponent = this.inputs.toArray().find(input => input.focused);
|
||||
if (!input) {
|
||||
input = this.entities.toArray().find(input => input.input.focused);
|
||||
}
|
||||
if (input) {
|
||||
if(event.code === 'Enter') {
|
||||
if (input instanceof EntitiesSelectionComponent) {
|
||||
input.input.focus(false, event);
|
||||
} else {
|
||||
|
@ -56,7 +56,6 @@ export class AdvancedSearchInputComponent implements AfterContentInit, OnDestroy
|
|||
this.searchEmitter.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
|
|
@ -19,7 +19,15 @@ import {EnvProperties} from "../../utils/properties/env-properties";
|
|||
import {properties} from "../../../../environments/environment";
|
||||
import {ClickEvent} from "../../utils/click/click-outside-or-esc.directive";
|
||||
|
||||
export type InputType = 'text' | 'URL' | 'logoURL' | 'autocomplete' | 'autocomplete_soft' | 'textarea' | 'select' | 'chips';
|
||||
export type InputType =
|
||||
'text'
|
||||
| 'URL'
|
||||
| 'logoURL'
|
||||
| 'autocomplete'
|
||||
| 'autocomplete_soft'
|
||||
| 'textarea'
|
||||
| 'select'
|
||||
| 'chips';
|
||||
|
||||
export interface Option {
|
||||
icon?: string,
|
||||
|
@ -70,7 +78,8 @@ declare var UIkit;
|
|||
</ng-container>
|
||||
<ng-container *ngIf="!placeholderInfo?.static">
|
||||
<div *ngIf="!getLabel(formControl.value)" class="input uk-text-truncate">No value selected</div>
|
||||
<div *ngIf="getLabel(formControl.value)" class="input uk-text-truncate">{{getLabel(formControl.value)}}</div>
|
||||
<div *ngIf="getLabel(formControl.value)"
|
||||
class="input uk-text-truncate">{{getLabel(formControl.value)}}</div>
|
||||
</ng-container>
|
||||
</ng-template>
|
||||
<ng-template [ngIf]="type === 'autocomplete'">
|
||||
|
@ -84,30 +93,35 @@ declare var UIkit;
|
|||
</ng-template>
|
||||
<ng-template [ngIf]="type === 'chips'">
|
||||
<div class="uk-grid uk-grid-small uk-grid-row-collapse uk-width-expand" uk-grid>
|
||||
<div *ngFor="let chip of formAsArray.controls; let i=index" [class.uk-hidden]="!focused && i > 0" class="chip">
|
||||
<div *ngFor="let chip of formAsArray.controls; let i=index" [class.uk-hidden]="!focused && i > 0"
|
||||
class="chip">
|
||||
<div class="uk-label uk-flex uk-flex-middle">
|
||||
<span class="uk-text-truncate uk-width-expand">{{getLabel(chip.value)}}</span>
|
||||
<icon (click)="remove(i, $event)" class="uk-link-text uk-margin-small-left clickable" [flex]="true"
|
||||
name="close" ratio="0.7"></icon>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="searchControl && (focused || formAsArray.length === 0)" class="uk-width-small uk-flex uk-flex-column uk-flex-center">
|
||||
<div *ngIf="searchControl && (focused || formAsArray.length === 0)"
|
||||
class="uk-width-small uk-flex uk-flex-column uk-flex-center">
|
||||
<input #searchInput class="input" [class.search]="searchControl.value"
|
||||
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
||||
[formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
||||
</div>
|
||||
<div *ngIf="!focused && formAsArray.length > 1" class="uk-width-expand uk-flex uk-flex-column uk-flex-center more">
|
||||
<div *ngIf="!focused && formAsArray.length > 1"
|
||||
class="uk-width-expand uk-flex uk-flex-column uk-flex-center more">
|
||||
+ {{(formAsArray.length - 1)}} more
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
<div *ngIf="(formControl.disabled && disabledIcon) || icon || (type === 'select' && selectArrow) || type === 'autocomplete'"
|
||||
<div
|
||||
*ngIf="(formControl.disabled && disabledIcon) || icon || (type === 'select' && selectArrow) || type === 'autocomplete'"
|
||||
class="uk-margin-left icon">
|
||||
<icon *ngIf="formControl.disabled && disabledIcon" [name]="disabledIcon" [flex]="true"></icon>
|
||||
<ng-template [ngIf]="formControl.enabled">
|
||||
<icon *ngIf="!formControl.value && icon" [name]="icon" [flex]="true"></icon>
|
||||
<icon *ngIf="!icon && type === 'select' && selectArrow" name="arrow_drop_down" [flex]="true"></icon>
|
||||
<button *ngIf="searchControl?.value && type === 'autocomplete'" class="uk-close uk-icon" (click)="resetSearch($event)">
|
||||
<button *ngIf="searchControl?.value && type === 'autocomplete'" class="uk-close uk-icon"
|
||||
(click)="resetSearch($event)">
|
||||
<icon [flex]="true" name="close"></icon>
|
||||
</button>
|
||||
</ng-template>
|
||||
|
@ -121,7 +135,8 @@ declare var UIkit;
|
|||
<div class="options uk-dropdown" *ngIf="filteredOptions && filteredOptions.length > 0 && opened" #optionBox
|
||||
uk-dropdown="pos: bottom-justify; mode: none; offset: 15; boundary-align: true;" [attr.boundary]="'#' + id">
|
||||
<ul class="uk-nav uk-dropdown-nav">
|
||||
<li *ngFor="let option of filteredOptions; let i=index" [class.uk-active]="(formControl.value === option.value) || selectedIndex === i"
|
||||
<li *ngFor="let option of filteredOptions; let i=index"
|
||||
[class.uk-active]="(formControl.value === option.value) || selectedIndex === i"
|
||||
[attr.uk-tooltip]="(tooltip)?('title: ' + option.label + ';'):null">
|
||||
<a (click)="selectOption(option, $event)">{{option.label}}</a>
|
||||
</li>
|
||||
|
@ -249,22 +264,31 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
}
|
||||
}
|
||||
|
||||
@HostListener('window:keydown', ['$event'])
|
||||
keyEvent(event: KeyboardEvent) {
|
||||
@HostListener('window:keydown.arrowUp', ['$event'])
|
||||
arrowUp(event: KeyboardEvent) {
|
||||
if (this.opened) {
|
||||
if(event.code === 'ArrowUp') {
|
||||
event.preventDefault();
|
||||
if (this.selectedIndex > 0) {
|
||||
this.selectedIndex--;
|
||||
this.optionBox.nativeElement.scrollBy(0, -34);
|
||||
}
|
||||
} else if(event.code === 'ArrowDown') {
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('window:keydown.arrowDown', ['$event'])
|
||||
arrowDown(event: KeyboardEvent) {
|
||||
if (this.opened) {
|
||||
event.preventDefault();
|
||||
if (this.selectedIndex < (this.filteredOptions.length - 1)) {
|
||||
this.selectedIndex++;
|
||||
this.optionBox.nativeElement.scrollBy(0, 34);
|
||||
}
|
||||
} else if(event.code === 'Enter') {
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('window:keydown.enter', ['$event'])
|
||||
enter(event: KeyboardEvent) {
|
||||
if (this.opened) {
|
||||
event.preventDefault();
|
||||
if (this.filteredOptions[this.selectedIndex]) {
|
||||
this.selectOption(this.filteredOptions[this.selectedIndex], event);
|
||||
|
@ -272,7 +296,6 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
click(event: ClickEvent) {
|
||||
this.focus(!event.clicked, event);
|
||||
|
|
|
@ -58,15 +58,13 @@ export class SearchInputComponent implements OnInit {
|
|||
constructor(private cdr: ChangeDetectorRef) {
|
||||
}
|
||||
|
||||
@HostListener('window:keydown', ['$event'])
|
||||
keyEvent(event: KeyboardEvent) {
|
||||
@HostListener('window:keydown.enter', ['$event'])
|
||||
enter(event: KeyboardEvent) {
|
||||
if(this.input.focused) {
|
||||
if(event.code === 'Enter') {
|
||||
event.preventDefault();
|
||||
this.search(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
click(event: ClickEvent) {
|
||||
if(this.expandable && !this.disabled) {
|
||||
|
|
|
@ -13,7 +13,7 @@ export class ClickOutsideOrEsc {
|
|||
|
||||
constructor(private elementRef: ElementRef) {}
|
||||
|
||||
@HostListener('document:click', ['$event'])
|
||||
@HostListener('click', ['$event'])
|
||||
click(event) {
|
||||
if(event.isTrusted) {
|
||||
this.clickOutside.emit({
|
||||
|
@ -23,13 +23,11 @@ export class ClickOutsideOrEsc {
|
|||
}
|
||||
}
|
||||
|
||||
@HostListener('window:keydown', ['$event'])
|
||||
keyEvent(event: KeyboardEvent) {
|
||||
if(event.code === 'Escape') {
|
||||
@HostListener('window:keydown.escape', ['$event'])
|
||||
esc(event: KeyboardEvent) {
|
||||
this.clickOutside.emit({
|
||||
event: event,
|
||||
clicked: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue