diff --git a/packages/nc-gui/components/cell/MultiSelect.vue b/packages/nc-gui/components/cell/MultiSelect.vue index ffc70435e9..9fa036468b 100644 --- a/packages/nc-gui/components/cell/MultiSelect.vue +++ b/packages/nc-gui/components/cell/MultiSelect.vue @@ -48,7 +48,7 @@ const isOpen = ref(false) const isKanban = inject(IsKanbanInj, ref(false)) -const options = computed(() => { +const options = computed<(SelectOptionType & { value?: string })[]>(() => { if (column?.value.colOptions) { const opts = column.value.colOptions ? (column.value.colOptions as SelectOptionsType).options.filter((el: SelectOptionType) => el.title !== '') || [] @@ -164,10 +164,15 @@ useSelectedCellKeyupListener(active, (e) => { const searchVal = ref() const { $api } = useNuxtApp() -const {getMeta} = useMetas() +const { getMeta } = useMetas() async function addIfMissingAndSave() { - const newOptValue = aselect.value?.$el?.querySelector('.ant-select-selection-search-input')?.value + const searchInput = aselect.value?.$el?.querySelector('.ant-select-selection-search-input') + + if (!searchInput) return false + + const newOptValue = searchInput?.value + if (newOptValue && !options.value.some((o) => o.title === newOptValue)) { const newOptions = [...options.value] newOptions.push({ title: newOptValue, value: newOptValue }) @@ -179,6 +184,7 @@ async function addIfMissingAndSave() { await getMeta(column.value.fk_model_id!, true) vModel.value = [...vModel.value, newOptValue] + searchInput.value = '' } } diff --git a/packages/nc-gui/components/cell/SingleSelect.vue b/packages/nc-gui/components/cell/SingleSelect.vue index bc216b7b4c..95e85f85a4 100644 --- a/packages/nc-gui/components/cell/SingleSelect.vue +++ b/packages/nc-gui/components/cell/SingleSelect.vue @@ -60,12 +60,17 @@ const options = computed<(SelectOptionType & { value: string })[]>(() => { return [] }) -const handleKeys = (e: KeyboardEvent) => { +const handleKeys = async (e: KeyboardEvent) => { switch (e.key) { case 'Escape': e.preventDefault() isOpen.value = false break + case 'Enter': + e.preventDefault() + if (await addIfMissingAndSave()) + e.stopPropagation() + break } } @@ -102,8 +107,12 @@ useSelectedCellKeyupListener(active, (e) => { const val = ref() const { $api } = useNuxtApp() -const addIfMissingAndSave = async () => { - const newOptValue = aselect.value?.$el?.querySelector('.ant-select-selection-search-input')?.value +async function addIfMissingAndSave() { + const searchInput = aselect.value?.$el?.querySelector('.ant-select-selection-search-input') + + if(!searchInput) return false + + const newOptValue = searchInput?.value if (newOptValue && !options.value.some((o) => o.title === newOptValue)) { options.value.push({ title: newOptValue, value: newOptValue }) @@ -117,6 +126,24 @@ const addIfMissingAndSave = async () => {