Browse Source

feat(gui): add shortcuts to navigate bw rows in expanded form

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5184/head
Pranav C 2 years ago
parent
commit
9212b5876d
  1. 19
      packages/nc-gui/components/smartsheet/expanded-form/index.vue
  2. 6
      packages/nc-gui/composables/useSelectedCellKeyupListener/index.ts

19
packages/nc-gui/components/smartsheet/expanded-form/index.vue

@ -22,6 +22,7 @@ import {
useVModel, useVModel,
watch, watch,
} from '#imports' } from '#imports'
import { useActiveKeyupListener } from '~/composables/useSelectedCellKeyupListener'
import type { Row } from '~/lib' import type { Row } from '~/lib'
interface Props { interface Props {
@ -157,6 +158,24 @@ const cellWrapperEl = ref<HTMLElement>()
onMounted(() => { onMounted(() => {
setTimeout(() => (cellWrapperEl.value?.querySelector('input,select,textarea') as HTMLInputElement)?.focus()) setTimeout(() => (cellWrapperEl.value?.querySelector('input,select,textarea') as HTMLInputElement)?.focus())
}) })
// attach keyboard listeners to switch between rows
// using alt + left/right arrow keys
useActiveKeyupListener(
isExpanded,
(e: KeyboardEvent) => {
if (!e.altKey) return
if (e.key === 'ArrowLeft') {
e.stopPropagation()
emits('prev')
} else if (e.key === 'ArrowRight') {
e.stopPropagation()
emits('next')
}
},
{ immediate: true },
)
</script> </script>
<script lang="ts"> <script lang="ts">

6
packages/nc-gui/composables/useSelectedCellKeyupListener/index.ts

@ -1,15 +1,15 @@
import { isClient } from '@vueuse/core' import { isClient } from '@vueuse/core'
import type { Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
function useSelectedCellKeyupListener( function useSelectedCellKeyupListener(
selected: Ref<boolean>, selected: Ref<boolean | undefined> | ComputedRef<boolean | undefined>,
handler: (e: KeyboardEvent) => void, handler: (e: KeyboardEvent) => void,
{ immediate = false }: { immediate?: boolean } = {}, { immediate = false }: { immediate?: boolean } = {},
) { ) {
if (isClient) { if (isClient) {
watch( watch(
selected, selected,
(nextVal: boolean, _: boolean, cleanup) => { (nextVal: boolean | undefined, _: boolean | undefined, cleanup) => {
// bind listener when `selected` is truthy // bind listener when `selected` is truthy
if (nextVal) { if (nextVal) {
document.addEventListener('keydown', handler, true) document.addEventListener('keydown', handler, true)

Loading…
Cancel
Save