feat: add ctrl+f as hotkey to focus search field

This commit is contained in:
4gray committed 2020-12-18 20:46:06 +01:00
1 parent 4abaeae8c2
commit cad162dc67
2 files changed
+19 -1

No files matched your search

@@ -4,6 +4,7 @@
<mat-list-item>
<mat-form-field class="full-width">
<input
#search
matInput
placeholder="Search channel ({{
_channelList?.length
@@ -1,4 +1,10 @@
import { Component, Input } from '@angular/core';
import {
Component,
ElementRef,
HostListener,
Input,
ViewChild,
} from '@angular/core';
import { Channel, ChannelStore, ChannelQuery } from '../../../state';
import * as _ from 'lodash';
@@ -44,6 +50,17 @@ export class ChannelListContainerComponent {
name: '',
};
/** Search field element */
@ViewChild('search') searchElement: ElementRef;
/** Register ctrl+f as keyboard hotkey to focus the search input field */
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent): void {
if (event.key === 'f' && event.ctrlKey) {
this.searchElement.nativeElement.focus();
}
}
/**
* Creates an instance of ChannelListContainerComponent
* @param channelQuery akita's channel query