chore(CommandPalette): improve component

This commit is contained in:
Benjamin Canac
2022-07-18 17:31:54 +02:00
parent d9f08b99ca
commit b44e3af422
2 changed files with 6 additions and 15 deletions

View File

@@ -2,7 +2,6 @@
<Combobox
:model-value="modelValue"
:multiple="multiple"
:nullable="nullable"
@update:model-value="onSelect"
>
<div class="flex flex-col flex-1 min-h-0 divide-y divide-gray-100 dark:divide-gray-800">
@@ -43,7 +42,6 @@ import { defu } from 'defu'
import type { UseFuseOptions } from '@vueuse/integrations/useFuse'
import type { Group, Command } from '../../types/command-palette'
import CommandPaletteGroup from './CommandPaletteGroup.vue'
import { useRouter } from '#imports'
const props = defineProps({
modelValue: {
@@ -54,10 +52,6 @@ const props = defineProps({
type: Boolean,
default: false
},
nullable: {
type: Boolean,
default: false
},
groups: {
type: Array as PropType<Group[]>,
default: () => []
@@ -124,16 +118,14 @@ function activateFirstOption () {
}, 0)
}
function onSelect (option: Command) {
if (option.disabled) {
return
}
function onSelect (option: Command | Command[]) {
emit('update:modelValue', option)
// waiting for modal to be closed
if (!option.prevent) {
query.value = ''
// Clear input after selection
if (!props.multiple) {
setTimeout(() => {
query.value = ''
}, 0)
}
}

View File

@@ -9,7 +9,6 @@ export interface Command {
avatar?: string
chip?: string
disabled?: boolean
prevent?: boolean
shortcuts?: string[]
}