refactor(core): add stub for addEventListener in useWindow

This commit is contained in:
braks
2023-10-30 13:36:07 +01:00
committed by Braks
parent 4ae371afbb
commit 2a407f59e3
4 changed files with 27 additions and 24 deletions
+3 -5
View File
@@ -72,11 +72,9 @@ export function useKeyPress(keyFilter: MaybeRefOrGetter<KeyFilter | null>, onCha
watch(
() => toValue(keyFilter),
(nextKeyFilter, previousKeyFilter) => {
if (window && typeof window.addEventListener !== 'undefined') {
useEventListener(window, 'blur', () => {
isPressed.value = false
})
}
useEventListener(window, 'blur', () => {
isPressed.value = false
})
// if the previous keyFilter was a boolean but is now something else, we need to reset the isPressed value
if (isBoolean(previousKeyFilter) && !isBoolean(nextKeyFilter)) {
+6 -1
View File
@@ -4,6 +4,11 @@ export function useWindow(): UseWindow {
if (typeof window !== 'undefined') {
return window as UseWindow
} else {
return { chrome: false } as UseWindow
return {
chrome: false,
addEventListener(..._: Parameters<Window['addEventListener']>) {
// do nothing
},
} as UseWindow
}
}