mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
501 B
21 lines
501 B
2 years ago
|
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,
|
||
|
}
|
||
|
}
|