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).
108 lines
2.9 KiB
Vue
108 lines
2.9 KiB
Vue
<script setup lang="ts">
|
||
import {
|
||
Button,
|
||
ComboBox,
|
||
ComboBoxInputGroup,
|
||
ComboBoxPopover,
|
||
ComboBoxTrigger,
|
||
Description,
|
||
FieldError,
|
||
Form,
|
||
Input,
|
||
Label,
|
||
ListBox,
|
||
ListBoxItem,
|
||
ListBoxItemIndicator,
|
||
} from "@heroui-vue/components";
|
||
import { ref } from "vue";
|
||
|
||
const animals = [
|
||
{ id: "aardvark", name: "土豚" },
|
||
{ id: "cat", name: "猫" },
|
||
{ id: "dog", name: "狗" },
|
||
{ id: "kangaroo", name: "袋鼠" },
|
||
{ id: "panda", name: "熊猫" },
|
||
{ id: "snake", name: "蛇" },
|
||
];
|
||
|
||
const nativeMessage = ref<string | null>(null);
|
||
const ariaMessage = ref<string | null>(null);
|
||
|
||
function submitNative(event: Event) {
|
||
event.preventDefault();
|
||
nativeMessage.value = "已通过原生校验提交。";
|
||
}
|
||
|
||
function submitAria(event: Event) {
|
||
event.preventDefault();
|
||
ariaMessage.value = "已通过 ARIA 校验提交。";
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div class="flex flex-col gap-8">
|
||
<Form class="flex w-[256px] flex-col gap-4" @submit="submitNative">
|
||
<ComboBox
|
||
is-required
|
||
class="w-full"
|
||
name="animal"
|
||
validation-behavior="native"
|
||
>
|
||
<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>
|
||
<Description>值为空时阻止提交</Description>
|
||
<FieldError />
|
||
</ComboBox>
|
||
<Button class="w-fit" type="submit">提交</Button>
|
||
<p v-if="nativeMessage" class="text-sm text-muted">{{ nativeMessage }}</p>
|
||
</Form>
|
||
<Form class="flex w-[256px] flex-col gap-4" @submit="submitAria">
|
||
<ComboBox
|
||
is-required
|
||
class="w-full"
|
||
name="animal-aria"
|
||
validation-behavior="aria"
|
||
>
|
||
<Label>动物(ARIA 校验)</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>
|
||
<Description>实时显示错误,不阻止提交</Description>
|
||
<FieldError />
|
||
</ComboBox>
|
||
<Button class="w-fit" type="submit">提交</Button>
|
||
<p v-if="ariaMessage" class="text-sm text-muted">{{ ariaMessage }}</p>
|
||
</Form>
|
||
</div>
|
||
</template>
|