feat(combo-box): migrate ComboBox with input-owned focus and filtering
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).
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
ComboBox,
|
||||
ComboBoxInputGroup,
|
||||
ComboBoxPopover,
|
||||
ComboBoxTrigger,
|
||||
FieldError,
|
||||
Form,
|
||||
Input,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const submitted = ref(false);
|
||||
|
||||
function submit(event: Event) {
|
||||
const formData = new FormData(event.currentTarget as HTMLFormElement);
|
||||
const data: Record<string, string> = {};
|
||||
|
||||
formData.forEach((value, key) => {
|
||||
data[key] = value.toString();
|
||||
});
|
||||
|
||||
submitted.value = "animal" in data;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Form class="flex w-[256px] flex-col gap-4" @submit.prevent="submit">
|
||||
<ComboBox is-required class="w-full" name="animal">
|
||||
<Label>最喜欢的动物</Label>
|
||||
<ComboBoxInputGroup>
|
||||
<Input placeholder="搜索动物…" />
|
||||
<ComboBoxTrigger />
|
||||
</ComboBoxInputGroup>
|
||||
<ComboBoxPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="aardvark" text-value="土豚">
|
||||
土豚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="cat" text-value="猫">
|
||||
猫
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="dog" text-value="狗">
|
||||
狗
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="kangaroo" text-value="袋鼠">
|
||||
袋鼠
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="panda" text-value="熊猫">
|
||||
熊猫
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="snake" text-value="蛇">
|
||||
蛇
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</ComboBoxPopover>
|
||||
<FieldError />
|
||||
</ComboBox>
|
||||
<Button type="submit">提交</Button>
|
||||
<p v-if="submitted" role="status" class="text-sm text-success">
|
||||
表单提交成功!
|
||||
</p>
|
||||
</Form>
|
||||
</template>
|
||||
Reference in New Issue
Block a user