Files
heroui-vue/apps/docs/demos/autocomplete-email-recipients.vue
T
maoyingjie 3e9be13b19 fix(pickers): repair data-slot selectors and align demos with the baseline
The CSS port prefixed data-slot attribute values with hv-, so the compiled
selectors never matched the DOM and the ComboBox trigger chevron never
rotated. Only class names get the prefix; slot values stay byte-identical.

Also commit typed text as the value when allowsCustomValue finds no record,
restore the baseline search-field shell in all 24 Autocomplete demos, and
correct both doc pages against the pinned upstream sources.
2026-10-25 17:46:32 +08:00

117 lines
3.0 KiB
Vue

<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>未找到收件人</EmptyState>
</template>
</ListBox>
</AutocompleteFilter>
</AutocompletePopover>
</Autocomplete>
</template>