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