mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Use a typescript is function to extract event target node
This commit is contained in:
parent
0a8d6515f9
commit
c75c38b01b
1 changed files with 17 additions and 7 deletions
|
|
@ -419,15 +419,25 @@ export default function PdfArticleContainer(
|
|||
}
|
||||
)
|
||||
|
||||
function keyDownHandler(event: globalThis.KeyboardEvent) {
|
||||
type PossibleInputEventTarget = KeyboardEvent & {
|
||||
nodeName: string
|
||||
}
|
||||
|
||||
function isPossibleInputEventTarget(
|
||||
target: any
|
||||
): target is PossibleInputEventTarget {
|
||||
return (
|
||||
'nodeName' in target &&
|
||||
typeof target.nodeName == 'string' &&
|
||||
target.nodeName
|
||||
)
|
||||
}
|
||||
|
||||
function keyDownHandler(event: KeyboardEvent) {
|
||||
const inputs = ['input', 'select', 'button', 'textarea']
|
||||
|
||||
if (
|
||||
event.target &&
|
||||
'nodeName' in event.target &&
|
||||
typeof event.target.nodeName == 'string'
|
||||
) {
|
||||
const nodeName = (event.target.nodeName as string).toLowerCase()
|
||||
if (event.target && isPossibleInputEventTarget(event.target)) {
|
||||
const nodeName = event.target.nodeName.toLowerCase()
|
||||
if (inputs.indexOf(nodeName) != -1) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue