mirror of https://github.com/nocodb/nocodb
2 changed files with 33 additions and 0 deletions
@ -0,0 +1,20 @@
|
||||
import type { Ref } from 'vue' |
||||
import { onUnmounted, useEventListener } from '#imports' |
||||
|
||||
export function useSelectedCellKeyupListener(selected: Ref<boolean>, handler: (e: KeyboardEvent) => void) { |
||||
const cleanup: Ref<ReturnType<typeof useEventListener> | null> = ref(null) |
||||
|
||||
watch(selected, (value) => { |
||||
if (value) { |
||||
cleanup.value = useEventListener('keydown', handler) |
||||
} else { |
||||
cleanup.value?.() |
||||
} |
||||
}) |
||||
|
||||
onUnmounted(() => cleanup.value?.()) |
||||
|
||||
return { |
||||
cleanup, |
||||
} |
||||
} |
Loading…
Reference in new issue