From 07728342d8532de3dd64852c0f9ec10937882c2b Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 5 Nov 2022 13:21:35 +0530 Subject: [PATCH] fix: proper multi/single select behaviour with keyboard Signed-off-by: Pranav C --- .../nc-gui/components/cell/MultiSelect.vue | 39 +++++-------------- .../nc-gui/components/cell/SingleSelect.vue | 34 +++++++--------- .../nc-gui/components/smartsheet/Cell.vue | 4 +- .../nc-gui/components/smartsheet/Grid.vue | 8 ++-- 4 files changed, 30 insertions(+), 55 deletions(-) diff --git a/packages/nc-gui/components/cell/MultiSelect.vue b/packages/nc-gui/components/cell/MultiSelect.vue index 4e0664b2e1..6d5d704321 100644 --- a/packages/nc-gui/components/cell/MultiSelect.vue +++ b/packages/nc-gui/components/cell/MultiSelect.vue @@ -74,36 +74,19 @@ const selectedTitles = computed(() => ? typeof modelValue === 'string' ? isMysql ? modelValue.split(',').sort((a, b) => { - const opa = options.value.find((el) => el.title === a) - const opb = options.value.find((el) => el.title === b) - if (opa && opb) { - return opa.order! - opb.order! - } - return 0 - }) + const opa = options.value.find((el) => el.title === a) + const opb = options.value.find((el) => el.title === b) + if (opa && opb) { + return opa.order! - opb.order! + } + return 0 + }) : modelValue.split(',') : modelValue : [], ) - -const v = Math.floor(Math.random() *1000) - -const handleKeys = (e: KeyboardEvent) => { - console.log(`handleKeys ${v}`, e.key) - if (!active.value) return true - switch (e.key) { - case 'ArrowDown': - case 'ArrowUp': - if (isOpen.value) { - e.stopPropagation() - } - break - case 'Enter': - e.stopPropagation() - break - } -} +const v = Math.floor(Math.random() * 1000) const handleClose = (e: MouseEvent) => { if (aselect.value && !aselect.value.$el.contains(e.target)) { @@ -146,17 +129,14 @@ watch(isOpen, (n, _o) => { } }) - useSelectedCellKeyupListener(active, (e) => { switch (e.key) { case 'Escape': isOpen.value = false - select?.value?.blur() break case 'Enter': if (active.value && !isOpen.value) { isOpen.value = true - e.stopPropagation() } break } @@ -167,15 +147,16 @@ useSelectedCellKeyupListener(active, (e) => { (() => { return [] }) -const handleKeys = (e: KeyboardEvent) => { - switch (e.key) { - case 'Escape': - e.preventDefault() - isOpen.value = false - break - case 'ArrowDown': - case 'ArrowUp': - if (isOpen.value) e.stopPropagation() - break - case 'Enter': - isOpen.value = true - e.stopPropagation() - break - } -} - - const handleClose = (e: MouseEvent) => { if (aselect.value && !aselect.value.$el.contains(e.target)) { isOpen.value = false @@ -72,7 +54,6 @@ const handleClose = (e: MouseEvent) => { useEventListener(document, 'click', handleClose) - watch(isOpen, (n, _o) => { if (!n) { aselect.value?.$el?.querySelector('input')?.blur() @@ -80,6 +61,19 @@ watch(isOpen, (n, _o) => { aselect.value?.$el?.querySelector('input')?.focus() } }) + +useSelectedCellKeyupListener(active, (e) => { + switch (e.key) { + case 'Escape': + isOpen.value = false + break + case 'Enter': + if (active.value && !isOpen.value) { + isOpen.value = true + } + break + } +})