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.
20 lines
507 B
20 lines
507 B
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, true) |
|
} else { |
|
cleanup.value?.() |
|
} |
|
}) |
|
|
|
onUnmounted(() => cleanup.value?.()) |
|
|
|
return { |
|
cleanup, |
|
} |
|
}
|
|
|