From 7cfa6491fcc03070a22323c766f14e29a388d381 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 31 Oct 2022 11:24:46 +0530 Subject: [PATCH] feat(gui): On first click outside checkbox, just select cell. Do not toggle value Signed-off-by: Pranav C --- packages/nc-gui/components/cell/Checkbox.vue | 21 ++++++++++++++----- .../nc-gui/components/cell/MultiSelect.vue | 12 +++++------ .../nc-gui/components/cell/SingleSelect.vue | 6 +++--- .../nc-gui/components/smartsheet/Grid.vue | 15 +++++++++++-- .../composables/useMultiSelect/index.ts | 6 ++++++ 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/packages/nc-gui/components/cell/Checkbox.vue b/packages/nc-gui/components/cell/Checkbox.vue index f5d76f8703..cfc3013cf5 100644 --- a/packages/nc-gui/components/cell/Checkbox.vue +++ b/packages/nc-gui/components/cell/Checkbox.vue @@ -1,5 +1,13 @@ @@ -160,9 +160,9 @@ useSelectedCellKeyupListener(active, (e) => { :open="isOpen" :disabled="readOnly" :class="{ '!ml-[-8px]': readOnly }" - dropdown-class-name="nc-dropdown-multi-select-cell" + :dropdown-class-name="`nc-dropdown-multi-select-cell ${isOpen ? 'active' : ''}`" @keydown="handleKeys" - @click="isOpen = !isOpen" + @click="isOpen = active && !isOpen" > { break case 'ArrowDown': case 'ArrowUp': - e.stopPropagation() + if (isOpen.value) e.stopPropagation() break case 'Enter': isOpen.value = true @@ -85,10 +85,10 @@ watch(isOpen, (n, _o) => { :open="isOpen" :disabled="readOnly" :show-arrow="!readOnly && (active || vModel === null)" - dropdown-class-name="nc-dropdown-single-select-cell" + :dropdown-class-name="`nc-dropdown-single-select-cell ${isOpen ? 'active' : ''}`" @select="isOpen = false" @keydown="handleKeys" - @click="isOpen = !isOpen" + @click="isOpen = active && !isOpen" > { + console.log(e) + if (e.code === 'Space') { + if (selected.row !== null && !editEnabled) { + const row = data.value[selected.row] + expandForm(row) + return true + } + } + }, ) onMounted(loadGridViewColumns) @@ -234,7 +244,7 @@ const showLoading = ref(true) const skipRowRemovalOnCancel = ref(false) -const expandForm = (row: Row, state?: Record, fromToolbar = false) => { +function expandForm(row: Row, state?: Record, fromToolbar = false) { const rowId = extractPkFromRow(row.row, meta.value?.columns as ColumnType[]) if (rowId) { @@ -334,8 +344,9 @@ onClickOutside(smartTable, (e: PointerEvent) => { if (editEnabled && (isVirtualCol(activeCol) || activeCol.uidt === UITypes.JSON)) return // ignore unselecting if clicked inside or on the picker(Date, Time, DateTime, Year) + // or single/multi select options const activePickerEl = document.querySelector( - '.nc-picker-datetime.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 diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index 23f634af3a..f089a9aac9 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -18,6 +18,7 @@ export function useMultiSelect( clearCell: Function, makeEditable: Function, scrollToActiveCell?: (row?: number | null, col?: number | null) => void, + keyEventHandler?: Function, ) { const { t } = useI18n() @@ -126,6 +127,11 @@ export function useMultiSelect( }) const onKeyDown = async (e: KeyboardEvent) => { + // invoke the keyEventHandler if provided and return if it returns true + if (await keyEventHandler?.(e)) { + return + } + if ( !isNaN(selectedRows.startRow) && !isNaN(selectedRows.startCol) &&