Browse Source

feat(gui): On first click outside checkbox, just select cell. Do not toggle value

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4222/head
Pranav C 2 years ago
parent
commit
7cfa6491fc
  1. 21
      packages/nc-gui/components/cell/Checkbox.vue
  2. 12
      packages/nc-gui/components/cell/MultiSelect.vue
  3. 6
      packages/nc-gui/components/cell/SingleSelect.vue
  4. 15
      packages/nc-gui/components/smartsheet/Grid.vue
  5. 6
      packages/nc-gui/composables/useMultiSelect/index.ts

21
packages/nc-gui/components/cell/Checkbox.vue

@ -1,5 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { ActiveCellInj, ColumnInj, IsFormInj, ReadonlyInj, getMdiIcon, inject, useSelectedCellKeyupListener } from '#imports' import {
ActiveCellInj,
ColumnInj,
IsFormInj,
ReadonlyInj,
getMdiIcon,
inject,
useSelectedCellKeyupListener,
} from '#imports'
interface Props { interface Props {
// If the previous cell value was a text, the initial checkbox value is a string type // If the previous cell value was a text, the initial checkbox value is a string type
@ -15,6 +23,8 @@ const props = defineProps<Props>()
const emits = defineEmits<Emits>() const emits = defineEmits<Emits>()
const active = inject(ActiveCellInj, ref(false))
let vModel = $computed({ let vModel = $computed({
get: () => !!props.modelValue && props.modelValue !== '0' && props.modelValue !== 0, get: () => !!props.modelValue && props.modelValue !== '0' && props.modelValue !== 0,
set: (val) => emits('update:modelValue', val), set: (val) => emits('update:modelValue', val),
@ -37,13 +47,13 @@ const checkboxMeta = $computed(() => {
} }
}) })
function onClick() { function onClick(force?: boolean) {
if (!readOnly?.value) { if (!readOnly?.value && (force || active.value)) {
vModel = !vModel vModel = !vModel
} }
} }
useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e) => { useSelectedCellKeyupListener(active, (e) => {
switch (e.key) { switch (e.key) {
case 'Enter': case 'Enter':
onClick() onClick()
@ -62,7 +72,7 @@ useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e) => {
'nc-cell-hover-show': !vModel && !readOnly, 'nc-cell-hover-show': !vModel && !readOnly,
'opacity-0': readOnly && !vModel, 'opacity-0': readOnly && !vModel,
}" }"
@click="onClick" @click="onClick(false)"
> >
<div class="px-1 pt-1 rounded-full items-center" :class="{ 'bg-gray-100': !vModel, '!ml-[-8px]': readOnly }"> <div class="px-1 pt-1 rounded-full items-center" :class="{ 'bg-gray-100': !vModel, '!ml-[-8px]': readOnly }">
<Transition name="layout" mode="out-in" :duration="100"> <Transition name="layout" mode="out-in" :duration="100">
@ -71,6 +81,7 @@ useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e) => {
:style="{ :style="{
color: checkboxMeta.color, color: checkboxMeta.color,
}" }"
@click.stop="onClick(true)"
/> />
</Transition> </Transition>
</div> </div>

12
packages/nc-gui/components/cell/MultiSelect.vue

@ -94,7 +94,7 @@ const handleKeys = (e: KeyboardEvent) => {
break break
case 'ArrowDown': case 'ArrowDown':
case 'ArrowUp': case 'ArrowUp':
e.stopPropagation() if (isOpen.value) e.stopPropagation()
break break
case 'Enter': case 'Enter':
isOpen.value = true isOpen.value = true
@ -141,9 +141,9 @@ watch(isOpen, (n, _o) => {
}) })
useSelectedCellKeyupListener(active, (e) => { useSelectedCellKeyupListener(active, (e) => {
if (e.key === 'Enter') { if (e.key === 'Escape') {
e.stopPropagation() // e.stopPropagation()
isOpen.value = true isOpen.value = false
} }
}) })
</script> </script>
@ -160,9 +160,9 @@ useSelectedCellKeyupListener(active, (e) => {
:open="isOpen" :open="isOpen"
:disabled="readOnly" :disabled="readOnly"
:class="{ '!ml-[-8px]': 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" @keydown="handleKeys"
@click="isOpen = !isOpen" @click="isOpen = active && !isOpen"
> >
<a-select-option <a-select-option
v-for="op of options" v-for="op of options"

6
packages/nc-gui/components/cell/SingleSelect.vue

@ -52,7 +52,7 @@ const handleKeys = (e: KeyboardEvent) => {
break break
case 'ArrowDown': case 'ArrowDown':
case 'ArrowUp': case 'ArrowUp':
e.stopPropagation() if (isOpen.value) e.stopPropagation()
break break
case 'Enter': case 'Enter':
isOpen.value = true isOpen.value = true
@ -85,10 +85,10 @@ watch(isOpen, (n, _o) => {
:open="isOpen" :open="isOpen"
:disabled="readOnly" :disabled="readOnly"
:show-arrow="!readOnly && (active || vModel === null)" :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" @select="isOpen = false"
@keydown="handleKeys" @keydown="handleKeys"
@click="isOpen = !isOpen" @click="isOpen = active && !isOpen"
> >
<a-select-option <a-select-option
v-for="op of options" v-for="op of options"

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

@ -213,6 +213,16 @@ const { selectCell, selectBlock, selectedRange, clearRangeRows, startSelectRange
}) })
} }
}, },
(e: KeyboardEvent) => {
console.log(e)
if (e.code === 'Space') {
if (selected.row !== null && !editEnabled) {
const row = data.value[selected.row]
expandForm(row)
return true
}
}
},
) )
onMounted(loadGridViewColumns) onMounted(loadGridViewColumns)
@ -234,7 +244,7 @@ const showLoading = ref(true)
const skipRowRemovalOnCancel = ref(false) const skipRowRemovalOnCancel = ref(false)
const expandForm = (row: Row, state?: Record<string, any>, fromToolbar = false) => { function expandForm(row: Row, state?: Record<string, any>, fromToolbar = false) {
const rowId = extractPkFromRow(row.row, meta.value?.columns as ColumnType[]) const rowId = extractPkFromRow(row.row, meta.value?.columns as ColumnType[])
if (rowId) { if (rowId) {
@ -334,8 +344,9 @@ onClickOutside(smartTable, (e: PointerEvent) => {
if (editEnabled && (isVirtualCol(activeCol) || activeCol.uidt === UITypes.JSON)) return if (editEnabled && (isVirtualCol(activeCol) || activeCol.uidt === UITypes.JSON)) return
// 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
const activePickerEl = document.querySelector( 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 if (e.target && activePickerEl && (activePickerEl === e.target || activePickerEl?.contains(e.target as Element))) return

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

@ -18,6 +18,7 @@ export function useMultiSelect(
clearCell: Function, clearCell: Function,
makeEditable: Function, makeEditable: Function,
scrollToActiveCell?: (row?: number | null, col?: number | null) => void, scrollToActiveCell?: (row?: number | null, col?: number | null) => void,
keyEventHandler?: Function,
) { ) {
const { t } = useI18n() const { t } = useI18n()
@ -126,6 +127,11 @@ export function useMultiSelect(
}) })
const onKeyDown = async (e: KeyboardEvent) => { const onKeyDown = async (e: KeyboardEvent) => {
// invoke the keyEventHandler if provided and return if it returns true
if (await keyEventHandler?.(e)) {
return
}
if ( if (
!isNaN(selectedRows.startRow) && !isNaN(selectedRows.startRow) &&
!isNaN(selectedRows.startCol) && !isNaN(selectedRows.startCol) &&

Loading…
Cancel
Save