refactor(nodes): prevent crash when checking if input dom node

This commit is contained in:
braks
2022-10-08 14:16:20 +02:00
committed by Braks
parent fd8061ddcc
commit 2a6763cfe1

View File

@@ -1,16 +1,14 @@
import type { Ref } from 'vue'
import type { KeyFilter, MaybeRef } from '@vueuse/core'
import { isBoolean } from '@vueuse/core'
import { isBoolean, isFunction } from '@vueuse/core'
import useWindow from './useWindow'
function isInputDOMNode(event: KeyboardEvent): boolean {
const target = event.target as HTMLElement
const hasAttribute = isFunction(target.hasAttribute) ? target.hasAttribute('contenteditable') : false
const closest = isFunction(target.closest) ? target.closest('.nokey') : null
return (
['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) ||
target?.hasAttribute('contenteditable') ||
!!target?.closest('.nokey')
)
return ['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) || hasAttribute || !!closest
}
export default (keyFilter: MaybeRef<KeyFilter>, onChange?: (keyPressed: boolean) => void): Ref<boolean> => {