Skip to content

Commit

Permalink
feat: add ctrl+f as hotkey to focus search field
Browse files Browse the repository at this point in the history
  • Loading branch information
4gray committed Dec 18, 2020
1 parent 4abaeae commit cad162d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<mat-list-item>
<mat-form-field class="full-width">
<input
#search
matInput
placeholder="Search channel ({{
_channelList?.length
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cad162d

Please sign in to comment.