Browse Source

refactor(gui): trigger scroll to cell only on key navigation

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4033/head
Pranav C 2 years ago
parent
commit
d11fa385c5
  1. 39
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 23
      packages/nc-gui/composables/useMultiSelect/index.ts

39
packages/nc-gui/components/smartsheet/Grid.vue

@ -107,6 +107,19 @@ const { selectCell, selectBlock, selectedRange, clearRangeRows, startSelectRange
isPkAvail,
clearCell,
makeEditable,
() => {
if (selected.row !== null && selected.col !== null) {
// get active cell
const td = tbodyEl.value?.querySelectorAll('tr')[selected.row]?.querySelectorAll('td')[selected.col + 1]
if (!td) return
// scroll into the active cell
td.scrollIntoView({
behavior: 'smooth',
block: 'end',
inline: 'end',
})
}
},
)
onMounted(loadGridViewColumns)
@ -353,19 +366,19 @@ watch(
const tbodyEl = ref<HTMLElement>()
watch([() => selected.row, () => selected.col], ([row, col]) => {
if (row !== null && col !== null) {
// get active cell
const td = tbodyEl.value?.querySelectorAll('tr')[row]?.querySelectorAll('td')[col + 1]
if (!td) return
// scroll into the active cell
td.scrollIntoView({
behavior: 'smooth',
block: 'end',
inline: 'end',
})
}
})
// watch([() => selected.row, () => selected.col], ([row, col]) => {
// if (row !== null && col !== null) {
// // get active cell
// const td = tbodyEl.value?.querySelectorAll('tr')[row]?.querySelectorAll('td')[col + 1]
// if (!td) return
// // scroll into the active cell
// td.scrollIntoView({
// behavior: 'smooth',
// block: 'end',
// inline: 'end',
// })
// }
// })
</script>
<template>

23
packages/nc-gui/composables/useMultiSelect/index.ts

@ -17,6 +17,7 @@ export function useMultiSelect(
isPkAvail: MaybeRef<boolean>,
clearCell: Function,
makeEditable: Function,
scrollToActiveCell?: () => void,
) {
const { t } = useI18n()
@ -39,6 +40,7 @@ export function useMultiSelect(
clearRangeRows()
selected.row = row
selected.col = col
scrollToActiveCell?.()
}
function selectBlock(row: number, col: number) {
@ -159,6 +161,7 @@ export function useMultiSelect(
selected.col = 0
}
}
scrollToActiveCell?.()
break
/** on enter key press make cell editable */
case 'Enter':
@ -178,25 +181,37 @@ export function useMultiSelect(
case 'ArrowRight':
e.preventDefault()
clearRangeRows()
if (selected.col < unref(columnLength) - 1) selected.col++
if (selected.col < unref(columnLength) - 1) {
selected.col++
scrollToActiveCell?.()
}
break
case 'ArrowLeft':
clearRangeRows()
e.preventDefault()
clearRangeRows()
if (selected.col > 0) selected.col--
if (selected.col > 0) {
selected.col--
scrollToActiveCell?.()
}
break
case 'ArrowUp':
clearRangeRows()
e.preventDefault()
clearRangeRows()
if (selected.row > 0) selected.row--
if (selected.row > 0) {
selected.row--
scrollToActiveCell?.()
}
break
case 'ArrowDown':
clearRangeRows()
e.preventDefault()
clearRangeRows()
if (selected.row < unref(data).length - 1) selected.row++
if (selected.row < unref(data).length - 1) {
selected.row++
scrollToActiveCell?.()
}
break
default:
{

Loading…
Cancel
Save