fix(command): add generic

This commit is contained in:
axuj 2024-07-26 13:13:48 +08:00
parent 0ee23fb53d
commit 1830363294
3 changed files with 13 additions and 7 deletions

View File

@ -92,7 +92,7 @@ const selectedTeam = ref<Team>(groups[0].teams[0])
</Button>
</PopoverTrigger>
<PopoverContent class="w-[200px] p-0">
<Command :filter-function="(list, term) => list.filter(i => i.label?.toLowerCase()?.includes(term)) ">
<Command :filter-function="(list:typeof groups, term:string) => list.filter(i => i.label?.toLowerCase()?.includes(term)) ">
<CommandList>
<CommandInput placeholder="Search team..." />
<CommandEmpty>No team found.</CommandEmpty>

View File

@ -1,12 +1,15 @@
<script setup lang="ts">
<script lang="ts">
type AcceptableValue = string | number | boolean | Record<string, any>
</script>
<script setup lang="ts" generic="T extends AcceptableValue">
import { type HTMLAttributes, computed } from 'vue'
import type { ComboboxRootEmits, ComboboxRootProps } from 'radix-vue'
import { ComboboxRoot, useForwardPropsEmits } from 'radix-vue'
import { cn } from '@/lib/utils'
const props = withDefaults(defineProps<ComboboxRootProps & { class?: HTMLAttributes['class'] }>(), {
const props = withDefaults(defineProps<ComboboxRootProps<T> & { class?: HTMLAttributes['class'] }>(), {
open: true,
modelValue: '',
})
const emits = defineEmits<ComboboxRootEmits>()

View File

@ -1,12 +1,15 @@
<script setup lang="ts">
<script lang="ts">
type AcceptableValue = string | number | boolean | Record<string, any>
</script>
<script setup lang="ts" generic="T extends AcceptableValue">
import { type HTMLAttributes, computed } from 'vue'
import type { ComboboxRootEmits, ComboboxRootProps } from 'radix-vue'
import { ComboboxRoot, useForwardPropsEmits } from 'radix-vue'
import { cn } from '@/lib/utils'
const props = withDefaults(defineProps<ComboboxRootProps & { class?: HTMLAttributes['class'] }>(), {
const props = withDefaults(defineProps<ComboboxRootProps<T> & { class?: HTMLAttributes['class'] }>(), {
open: true,
modelValue: '',
})
const emits = defineEmits<ComboboxRootEmits>()