mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-31 17:58:41 -04:00
Refactored search keyboard handlers
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user