Fixed content tabs stealing keyboard access to search

This commit is contained in:
squidfunk
2021-10-10 23:13:40 +02:00
parent 77c62c9b55
commit 03ff04b339
10 changed files with 32 additions and 22 deletions

View File

@@ -56,16 +56,26 @@ export interface Keyboard {
* Check whether an element may receive keyboard input
*
* @param el - Element
* @param type - Key type
*
* @returns Test result
*/
function isSusceptibleToKeyboard(el: HTMLElement): boolean {
switch (el.tagName) {
function isSusceptibleToKeyboard(
el: HTMLElement, type: string
): boolean {
switch (el.constructor) {
/* Form elements */
case "INPUT":
case "SELECT":
case "TEXTAREA":
/* Input elements */
case HTMLInputElement:
/* @ts-expect-error - omit unnecessary type cast */
if (el.type === "radio")
return /^Arrow/.test(type)
else
return true
/* Select element and textarea */
case HTMLSelectElement:
case HTMLTextAreaElement:
return true
/* Everything else */
@@ -95,11 +105,11 @@ export function watchKeyboard(): Observable<Keyboard> {
ev.stopPropagation()
}
} as Keyboard)),
filter(({ mode }) => {
filter(({ mode, type }) => {
if (mode === "global") {
const active = getActiveElement()
if (typeof active !== "undefined")
return !isSusceptibleToKeyboard(active)
return !isSusceptibleToKeyboard(active, type)
}
return true
}),

View File

@@ -163,7 +163,7 @@ export async function handler(
* Worker
* ------------------------------------------------------------------------- */
/* @ts-ignore - expose Lunr.js in global scope, or stemmers will not work */
/* @ts-expect-error - expose Lunr.js in global scope, or stemmers won't work */
self.lunr = lunr
/* Handle messages */