Refactored search keyboard handlers

This commit is contained in:
squidfunk
2020-02-14 11:33:59 +01:00
parent 8c92565b7b
commit f150a6c9b5
6 changed files with 108 additions and 108 deletions

View File

@@ -29,6 +29,25 @@ import { getActiveElement } from "../_"
* Functions
* ------------------------------------------------------------------------- */
/**
* Set element focus
*
* @param el - Element
* @param value - Whether the element should be focused
*
* @return Element offset
*/
export function setElementFocus(
el: HTMLElement, value: boolean = true
): void {
if (value)
el.focus()
else
el.blur()
}
/* ------------------------------------------------------------------------- */
/**
* Watch element focus
*

View File

@@ -31,7 +31,7 @@ import { filter, map, share } from "rxjs/operators"
* Key
*/
export interface Key {
code: string /* Key code */
type: string /* Key type */
claim(): void /* Key claim */
}
@@ -82,7 +82,7 @@ export function watchKeyboard(): Observable<Key> {
.pipe(
filter(ev => !(ev.shiftKey || ev.metaKey || ev.ctrlKey)),
map(ev => ({
code: ev.code,
type: ev.key,
claim() {
ev.preventDefault()
ev.stopPropagation()