Browse Source

feat(gui): open picker on pressing enter key nd close on escApe key press

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4222/head
Pranav C 2 years ago
parent
commit
5ec33a7883
  1. 15
      packages/nc-gui/components/cell/DatePicker.vue
  2. 15
      packages/nc-gui/components/cell/DateTimePicker.vue
  3. 6
      packages/nc-gui/components/cell/MultiSelect.vue
  4. 3
      packages/nc-gui/components/cell/Rating.vue
  5. 15
      packages/nc-gui/components/cell/TimePicker.vue
  6. 15
      packages/nc-gui/components/cell/YearPicker.vue
  7. 4
      packages/nc-gui/components/cell/attachment/index.vue

15
packages/nc-gui/components/cell/DatePicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { ColumnInj, ReadonlyInj, computed, inject, ref, watch } from '#imports' import { ActiveCellInj, ColumnInj, ReadonlyInj, computed, inject, ref, useSelectedCellKeyupListener, watch } from '#imports'
interface Props { interface Props {
modelValue?: string | null modelValue?: string | null
@ -57,6 +57,19 @@ watch(
) )
const placeholder = computed(() => (isDateInvalid ? 'Invalid date' : '')) const placeholder = computed(() => (isDateInvalid ? 'Invalid date' : ''))
useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e: KeyboardEvent) => {
switch (e.key) {
case 'Enter':
e.stopPropagation()
open.value = true
break
case 'Escape':
e.stopPropagation()
open.value = false
break
}
})
</script> </script>
<template> <template>

15
packages/nc-gui/components/cell/DateTimePicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { ReadonlyInj, inject, ref, useProject, watch } from '#imports' import { ActiveCellInj, ReadonlyInj, inject, ref, useProject, useSelectedCellKeyupListener, watch } from '#imports'
interface Props { interface Props {
modelValue?: string | null modelValue?: string | null
@ -56,6 +56,19 @@ watch(
}, },
{ flush: 'post' }, { flush: 'post' },
) )
useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e: KeyboardEvent) => {
switch (e.key) {
case 'Enter':
e.stopPropagation()
open.value = true
break
case 'Escape':
e.stopPropagation()
open.value = false
break
}
})
</script> </script>
<template> <template>

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

@ -14,6 +14,7 @@ import {
ref, ref,
useEventListener, useEventListener,
useProject, useProject,
useSelectedCellKeyupListener,
watch, watch,
} from '#imports' } from '#imports'
import MdiCloseCircle from '~icons/mdi/close-circle' import MdiCloseCircle from '~icons/mdi/close-circle'
@ -139,8 +140,9 @@ watch(isOpen, (n, _o) => {
if (!n) aselect.value?.$el.blur() if (!n) aselect.value?.$el.blur()
}) })
useEventListener(document, 'keydown', (e) => { useSelectedCellKeyupListener(active, (e) => {
if (active.value && e.key === 'Enter') { if (e.key === 'Enter') {
e.stopPropagation()
isOpen.value = true isOpen.value = true
} }
}) })

3
packages/nc-gui/components/cell/Rating.vue

@ -30,8 +30,9 @@ const vModel = computed({
set: (val) => emits('update:modelValue', val), set: (val) => emits('update:modelValue', val),
}) })
useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e) => { useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e: KeyboardEvent) => {
if (/^\d$/.test(e.key)) { if (/^\d$/.test(e.key)) {
e.stopPropagation()
vModel.value = +e.key === +vModel.value ? 0 : +e.key vModel.value = +e.key === +vModel.value ? 0 : +e.key
} }
}) })

15
packages/nc-gui/components/cell/TimePicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { ReadonlyInj, inject, onClickOutside, useProject, watch } from '#imports' import { ActiveCellInj, ReadonlyInj, inject, onClickOutside, useProject, useSelectedCellKeyupListener, watch } from '#imports'
interface Props { interface Props {
modelValue?: string | null | undefined modelValue?: string | null | undefined
@ -65,6 +65,19 @@ watch(
}, },
{ flush: 'post' }, { flush: 'post' },
) )
useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e: KeyboardEvent) => {
switch (e.key) {
case 'Enter':
e.stopPropagation()
open.value = true
break
case 'Escape':
e.stopPropagation()
open.value = false
break
}
})
</script> </script>
<template> <template>

15
packages/nc-gui/components/cell/YearPicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { ReadonlyInj, computed, inject, onClickOutside, ref, watch } from '#imports' import { ActiveCellInj, ReadonlyInj, computed, inject, onClickOutside, ref, useSelectedCellKeyupListener, watch } from '#imports'
interface Props { interface Props {
modelValue?: number | string | null modelValue?: number | string | null
@ -55,6 +55,19 @@ watch(
) )
const placeholder = computed(() => (isYearInvalid ? 'Invalid year' : '')) const placeholder = computed(() => (isYearInvalid ? 'Invalid year' : ''))
useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e: KeyboardEvent) => {
switch (e.key) {
case 'Enter':
e.stopPropagation()
open.value = true
break
case 'Escape':
e.stopPropagation()
open.value = false
break
}
})
</script> </script>
<template> <template>

4
packages/nc-gui/components/cell/attachment/index.vue

@ -1,9 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { onKeyDown } from '@vueuse/core' import { onKeyDown } from '@vueuse/core'
import { useSelectedCellKeyupListener } from '~/composables/useSelectedCellKeyupListener'
import { ActiveCellInj } from '~/context'
import { useProvideAttachmentCell } from './utils' import { useProvideAttachmentCell } from './utils'
import { useSortable } from './sort' import { useSortable } from './sort'
import { useSelectedCellKeyupListener } from '~/composables/useSelectedCellKeyupListener'
import { ActiveCellInj } from '~/context'
import { import {
DropZoneRef, DropZoneRef,
IsGalleryInj, IsGalleryInj,

Loading…
Cancel
Save