Browse Source

fix: prevent cell switch on keypress when picker, dropdown or LTAR list is in open state

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4222/head
Pranav C 2 years ago
parent
commit
326e6ab7ce
  1. 16
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 21
      packages/nc-gui/components/virtual-cell/components/ListItems.vue
  3. 6
      packages/nc-gui/composables/useSelectedCellKeyupListener/index.ts

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

@ -172,6 +172,13 @@ const { selectCell, selectBlock, selectedRange, clearRangeRows, startSelectRange
makeEditable, makeEditable,
scrollToCell, scrollToCell,
(e: KeyboardEvent) => { (e: KeyboardEvent) => {
// ignore navigating if picker(Date, Time, DateTime, Year)
// or single/multi select options is open
const activePickerOrDropdownEl = document.querySelector(
'.nc-picker-datetime.active,.nc-dropdown-single-select-cell.active,.nc-dropdown-multi-select-cell.active,.nc-picker-date.active,.nc-picker-year.active,.nc-picker-time.active',
)
if (activePickerOrDropdownEl) return true
const cmdOrCtrl = isMac() ? e.metaKey : e.ctrlKey const cmdOrCtrl = isMac() ? e.metaKey : e.ctrlKey
if (e.key === 'Space') { if (e.key === 'Space') {
if (selected.row !== null && !editEnabled) { if (selected.row !== null && !editEnabled) {
@ -373,10 +380,15 @@ onClickOutside(smartTable, (e) => {
// ignore unselecting if clicked inside or on the picker(Date, Time, DateTime, Year) // ignore unselecting if clicked inside or on the picker(Date, Time, DateTime, Year)
// or single/multi select options // or single/multi select options
const activePickerEl = document.querySelector( const activePickerOrDropdownEl = document.querySelector(
'.nc-picker-datetime.active,.nc-dropdown-single-select-cell.active,.nc-dropdown-multi-select-cell.active,.nc-picker-date.active,.nc-picker-year.active,.nc-picker-time.active', '.nc-picker-datetime.active,.nc-dropdown-single-select-cell.active,.nc-dropdown-multi-select-cell.active,.nc-picker-date.active,.nc-picker-year.active,.nc-picker-time.active',
) )
if (e.target && activePickerEl && (activePickerEl === e.target || activePickerEl?.contains(e.target as Element))) return if (
e.target &&
activePickerOrDropdownEl &&
(activePickerOrDropdownEl === e.target || activePickerOrDropdownEl?.contains(e.target as Element))
)
return
selected.row = null selected.row = null
selected.col = null selected.col = null

21
packages/nc-gui/components/virtual-cell/components/ListItems.vue

@ -106,6 +106,10 @@ watch(expandedFormDlg, (nexVal) => {
useSelectedCellKeyupListener(vModel, (e: KeyboardEvent) => { useSelectedCellKeyupListener(vModel, (e: KeyboardEvent) => {
switch (e.key) { switch (e.key) {
case 'ArrowLeft':
case 'ArrowRight':
e.stopPropagation()
break
case 'ArrowUp': case 'ArrowUp':
selectedRowIndex.value = Math.max(0, selectedRowIndex.value - 1) selectedRowIndex.value = Math.max(0, selectedRowIndex.value - 1)
e.stopPropagation() e.stopPropagation()
@ -114,19 +118,18 @@ useSelectedCellKeyupListener(vModel, (e: KeyboardEvent) => {
selectedRowIndex.value = Math.min(childrenExcludedList.value?.list?.length - 1, selectedRowIndex.value + 1) selectedRowIndex.value = Math.min(childrenExcludedList.value?.list?.length - 1, selectedRowIndex.value + 1)
e.stopPropagation() e.stopPropagation()
break break
case 'Enter': case 'Enter': {
{ const selectedRow = childrenExcludedList.value?.list?.[selectedRowIndex.value]
const selectedRow = childrenExcludedList.value?.list?.[selectedRowIndex.value] if (selectedRow) {
if (selectedRow) { linkRow(selectedRow)
linkRow(selectedRow) e.stopPropagation()
e.stopPropagation()
}
} }
}
break break
} }
}) })
const activeRow = (el?: InstanceType<typeof Card>) => { const activeRow = (vNode?: InstanceType<typeof Card>) => {
el?.$el?.scrollIntoView({ block: 'nearest', inline: 'nearest' }) vNode?.$el?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
} }
</script> </script>

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

@ -6,15 +6,15 @@ export function useSelectedCellKeyupListener(selected: Ref<boolean>, handler: (e
watch(selected, (nextVal, _, cleanup) => { watch(selected, (nextVal, _, cleanup) => {
// bind listener when `selected` is truthy // bind listener when `selected` is truthy
if (nextVal) { if (nextVal) {
document.addEventListener('keyup', handler) document.addEventListener('keydown', handler, true)
// if `selected` is falsy then remove the event handler // if `selected` is falsy then remove the event handler
} else { } else {
document.removeEventListener('keyup', handler) document.removeEventListener('keydown', handler, true)
} }
// cleanup is called whenever the watcher is re-evaluated or stopped // cleanup is called whenever the watcher is re-evaluated or stopped
cleanup(() => { cleanup(() => {
document.removeEventListener('keyup', handler) document.removeEventListener('keydown', handler, true)
}) })
}) })
} }

Loading…
Cancel
Save