5e688680e9
Port the fixed-baseline Autocomplete onto the B02a collection protocol. The trigger is the single Tab entry; opening moves focus to the search box inside the popover, which owns filtering, aria-activedescendant and keyboard navigation while the list only tracks an active row. - Seven parts: root (field, value/open models, form value, owner wiring), trigger (anchor + activation), value (scoped slot with selectedItems and selectedText instead of copied item subtrees), indicator, clear button, popover (measured trigger width), filter (owns the search text and composes the inner SearchFieldInput into the combobox control). - Filter exposes input-value/update:inputValue/inputChange, matching ComboBox. - Confirming the active row in multiple mode now toggles it instead of replacing the accepted set (ComboBox shared the same bug). - ComboBox shows the accepted label on the first render via a display value that falls back to the selected record, so preselected fields are readable before the selection watcher runs (including SSR). - Popovers measure the anchor with a ResizeObserver because Reka does not publish the anchor size; the caller's root class is merged again so the trigger fills the field width. - 24 baseline previews, Chinese doc page, navigation, 17 behaviour tests, 5 demo/document contracts and an independent tarball consumption script for both pickers. Not included: the full bundler/NodeNext type matrix (B02d).
117 lines
3.3 KiB
Vue
117 lines
3.3 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from "vue";
|
|
import {
|
|
Autocomplete,
|
|
AutocompleteClearButton,
|
|
AutocompleteFilter,
|
|
AutocompleteIndicator,
|
|
AutocompletePopover,
|
|
AutocompleteTrigger,
|
|
AutocompleteValue,
|
|
EmptyState,
|
|
Header,
|
|
Label,
|
|
ListBox,
|
|
ListBoxItem,
|
|
ListBoxItemIndicator,
|
|
ListBoxSection,
|
|
SearchField,
|
|
SearchFieldGroup,
|
|
SearchFieldInput,
|
|
SearchFieldSearchIcon,
|
|
Separator,
|
|
} from "@heroui-vue/components";
|
|
|
|
const selectedKey = ref<string | null>(null);
|
|
</script>
|
|
|
|
<template>
|
|
<Autocomplete
|
|
v-model="selectedKey"
|
|
class="w-[256px]"
|
|
placeholder="选择一个国家"
|
|
selection-mode="single"
|
|
>
|
|
<Label>国家</Label>
|
|
<AutocompleteTrigger>
|
|
<AutocompleteValue />
|
|
<AutocompleteClearButton />
|
|
<AutocompleteIndicator />
|
|
</AutocompleteTrigger>
|
|
<AutocompletePopover>
|
|
<AutocompleteFilter>
|
|
<SearchField aria-label="搜索国家">
|
|
<SearchFieldGroup>
|
|
<SearchFieldSearchIcon />
|
|
<SearchFieldInput placeholder="搜索国家…" />
|
|
</SearchFieldGroup>
|
|
</SearchField>
|
|
<ListBox>
|
|
<ListBoxSection>
|
|
<Header>北美洲</Header>
|
|
<ListBoxItem id="usa" text-value="美国">
|
|
美国
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="canada" text-value="加拿大">
|
|
加拿大
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="mexico" text-value="墨西哥">
|
|
墨西哥
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
</ListBoxSection>
|
|
<Separator />
|
|
<ListBoxSection>
|
|
<Header>欧洲</Header>
|
|
<ListBoxItem id="uk" text-value="英国">
|
|
英国
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="france" text-value="法国">
|
|
法国
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="germany" text-value="德国">
|
|
德国
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="spain" text-value="西班牙">
|
|
西班牙
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="italy" text-value="意大利">
|
|
意大利
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
</ListBoxSection>
|
|
<Separator />
|
|
<ListBoxSection>
|
|
<Header>亚洲</Header>
|
|
<ListBoxItem id="japan" text-value="日本">
|
|
日本
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="china" text-value="中国">
|
|
中国
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="india" text-value="印度">
|
|
印度
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<ListBoxItem id="south-korea" text-value="韩国">
|
|
韩国
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
</ListBoxSection>
|
|
<template #empty>
|
|
<EmptyState class="p-1">未找到结果</EmptyState>
|
|
</template>
|
|
</ListBox>
|
|
</AutocompleteFilter>
|
|
</AutocompletePopover>
|
|
</Autocomplete>
|
|
</template>
|