feat(autocomplete): migrate Autocomplete with popover-owned filtering
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).
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const emails = [
|
||||
{
|
||||
email: "alice@example.com",
|
||||
id: "alice@example.com",
|
||||
name: "Alice Johnson",
|
||||
},
|
||||
{ email: "bob@example.com", id: "bob@example.com", name: "Bob Smith" },
|
||||
{
|
||||
email: "charlie@example.com",
|
||||
id: "charlie@example.com",
|
||||
name: "Charlie Brown",
|
||||
},
|
||||
{ email: "diana@example.com", id: "diana@example.com", name: "Diana Prince" },
|
||||
{ email: "eve@example.com", id: "eve@example.com", name: "Eve Wilson" },
|
||||
];
|
||||
|
||||
const selectedKeys = ref<TagKey[]>([]);
|
||||
|
||||
function onRemoveTags(keys: TagKey[]) {
|
||||
selectedKeys.value = selectedKeys.value.filter((key) => !keys.includes(key));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKeys"
|
||||
class="w-[256px]"
|
||||
placeholder="添加收件人"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>收件人</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup v-else size="sm" @remove="onRemoveTags">
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="item.textValue"
|
||||
>
|
||||
{{ item.textValue }}
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索邮箱"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索邮箱…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="entry in emails"
|
||||
:id="entry.id"
|
||||
:key="entry.id"
|
||||
:text-value="entry.email"
|
||||
>
|
||||
<div class="flex flex-col">
|
||||
<Label>{{ entry.name }}</Label>
|
||||
<Description>{{ entry.email }}</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到收件人</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
Reference in New Issue
Block a user