46e4df7e85
Port the fixed-baseline ComboBox onto the B02a collection protocol: the input keeps real DOM focus, the list only tracks an active row, and filtering reuses the owner filter instead of a second collection kernel. - Five parts: root (field text control, value/input/open models, form value, owner wiring), InputGroup (composes the caller's Input into the combobox control and anchors the popover), Trigger, Value, Popover. - Closed-state metadata is planned from the slot tree, so filtering, the initial value label and form-value="text" work before the list has mounted. - Selection text syncs on selection changes only, so allows-custom-value typing is not overwritten; read-only and disabled are injected onto the composed input because it reads the text-field protocol, not the field context. - 24 baseline previews, the Chinese doc page, navigation, 19 behaviour tests and 6 demo/document contracts. Async demo uses a local async source with abort, loading and incremental append (documented adaptations). Not included: independent tarball consumption (B02d).
60 lines
1.4 KiB
Vue
60 lines
1.4 KiB
Vue
<script setup lang="ts">
|
||
import { computed, ref } from "vue";
|
||
import {
|
||
ComboBox,
|
||
ComboBoxInputGroup,
|
||
ComboBoxPopover,
|
||
ComboBoxTrigger,
|
||
Input,
|
||
Label,
|
||
ListBox,
|
||
ListBoxItem,
|
||
ListBoxItemIndicator,
|
||
type ListBoxKey,
|
||
} from "@heroui-vue/components";
|
||
|
||
const animals = [
|
||
{ id: "cat", name: "猫" },
|
||
{ id: "dog", name: "狗" },
|
||
{ id: "bird", name: "鸟" },
|
||
{ id: "fish", name: "鱼" },
|
||
{ id: "hamster", name: "仓鼠" },
|
||
];
|
||
|
||
const selectedKey = ref<ListBoxKey | null>("cat");
|
||
|
||
const selectedAnimal = computed(() =>
|
||
animals.find((animal) => animal.id === selectedKey.value),
|
||
);
|
||
</script>
|
||
|
||
<template>
|
||
<div class="space-y-2">
|
||
<ComboBox
|
||
class="w-[256px]"
|
||
:selected-key="selectedKey"
|
||
@selection-change="selectedKey = $event"
|
||
>
|
||
<Label>动物(受控)</Label>
|
||
<ComboBoxInputGroup>
|
||
<Input placeholder="搜索动物…" />
|
||
<ComboBoxTrigger />
|
||
</ComboBoxInputGroup>
|
||
<ComboBoxPopover>
|
||
<ListBox>
|
||
<ListBoxItem
|
||
v-for="animal in animals"
|
||
:id="animal.id"
|
||
:key="animal.id"
|
||
:text-value="animal.name"
|
||
>
|
||
{{ animal.name }}
|
||
<ListBoxItemIndicator />
|
||
</ListBoxItem>
|
||
</ListBox>
|
||
</ComboBoxPopover>
|
||
</ComboBox>
|
||
<p class="text-sm text-muted">已选:{{ selectedAnimal?.name || "无" }}</p>
|
||
</div>
|
||
</template>
|