combobox

A multi-select with chips that cannot be removed

A multi-select with chips that cannot be removed

Загрузка превью…

src/combobox/c-combobox-15.vue

<script setup lang="ts">
import { ref } from "vue"
import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxEmpty, ComboboxItem, ComboboxList, ComboboxValue, useComboboxAnchor } from "@/components/ui/combobox"
import { Field } from "@/components/ui/field"

const frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"]
const anchor = useComboboxAnchor()
const selected = ref<string[]>([frameworks[0]!, frameworks[1]!])
</script>

<template>
  <Field class="max-w-xs">
    <Combobox
      multiple
      :model-value="selected"
      @update:model-value="(v) => (selected = v as unknown as string[])"
    >
      <ComboboxChips>
        <ComboboxValue v-slot="{ value }">
          <ComboboxChip v-for="v in (value as string[]) ?? []" :key="v" :show-remove="false">
            {{ v }}
          </ComboboxChip>
          <ComboboxChipsInput placeholder="Select frameworks..." />
        </ComboboxValue>
      </ComboboxChips>
      <ComboboxContent :anchor="anchor">
        <ComboboxEmpty>No items found.</ComboboxEmpty>
        <ComboboxList>
          <ComboboxItem v-for="item in frameworks" :key="item" :value="item">
            {{ item }}
          </ComboboxItem>
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  </Field>
</template>

Установка

npx shadcn-vue@latest add https://revueui.rootapi.dev/r/c-combobox-15.json

Зависимости реестра

Источник: порт из ReUI (Keenthemes, MIT)