3e9be13b19
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.
127 lines
4.4 KiB
Vue
127 lines
4.4 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 teammates = [
|
|
{ id: "sarah", name: "Sarah Chen", role: "产品设计" },
|
|
{ id: "marcus", name: "Marcus Lee", role: "工程" },
|
|
{ id: "priya", name: "Priya Patel", role: "数据科学" },
|
|
{ id: "jordan", name: "Jordan Kim", role: "客户成功" },
|
|
{ id: "alex", name: "Alex Rivera", role: "市场营销" },
|
|
];
|
|
|
|
const selectedKeys = ref<TagKey[]>([]);
|
|
|
|
const teammateOf = (key: unknown) =>
|
|
teammates.find((teammate) => teammate.id === key);
|
|
|
|
function onRemoveTags(keys: TagKey[]) {
|
|
selectedKeys.value = selectedKeys.value.filter((key) => !keys.includes(key));
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="w-full max-w-sm pt-6">
|
|
<Autocomplete
|
|
v-model="selectedKeys"
|
|
class="w-full gap-1.5"
|
|
placeholder="搜索团队成员..."
|
|
selection-mode="multiple"
|
|
>
|
|
<Label class="font-medium text-foreground">负责人</Label>
|
|
<Description>任务更新时将通知以下人员。</Description>
|
|
<AutocompleteTrigger
|
|
class="rounded-xl border border-border/80 bg-surface shadow-sm ring-1 ring-accent/5 transition-[box-shadow,border-color] focus-within:border-accent/25 focus-within:ring-2 focus-within:ring-accent/15 dark:border-border/90 dark:bg-surface dark:ring-accent/10 dark:focus-within:border-accent/35"
|
|
>
|
|
<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="teammateOf(item.key)?.name"
|
|
class="border border-accent/15 bg-accent/8 text-foreground dark:border-accent/25 dark:bg-accent/12"
|
|
>
|
|
{{ teammateOf(item.key)?.name }}
|
|
</Tag>
|
|
</TagGroupList>
|
|
</TagGroup>
|
|
</template>
|
|
</AutocompleteValue>
|
|
<AutocompleteClearButton />
|
|
<AutocompleteIndicator />
|
|
</AutocompleteTrigger>
|
|
<AutocompletePopover
|
|
class="overflow-hidden rounded-xl border border-border/80 bg-surface shadow-xl ring-1 ring-black/3 dark:border-border/90 dark:bg-surface dark:ring-white/5"
|
|
>
|
|
<AutocompleteFilter>
|
|
<SearchField
|
|
auto-focus
|
|
aria-label="按姓名或角色搜索"
|
|
name="search"
|
|
variant="secondary"
|
|
>
|
|
<SearchFieldGroup
|
|
class="border-b border-separator bg-surface-secondary/50"
|
|
>
|
|
<SearchFieldSearchIcon class="text-muted" />
|
|
<SearchFieldInput placeholder="按姓名或角色搜索..." />
|
|
<SearchFieldClearButton />
|
|
</SearchFieldGroup>
|
|
</SearchField>
|
|
<ListBox class="p-1.5">
|
|
<ListBoxItem
|
|
v-for="teammate in teammates"
|
|
:id="teammate.id"
|
|
:key="teammate.id"
|
|
:text-value="`${teammate.name} ${teammate.role}`"
|
|
class="rounded-lg data-[focused=true]:bg-accent/10 data-[selected=true]:bg-accent/5 dark:data-[focused=true]:bg-accent/15 dark:data-[selected=true]:bg-accent/8"
|
|
>
|
|
<div class="flex flex-col gap-0.5">
|
|
<span class="text-sm font-medium text-foreground">
|
|
{{ teammate.name }}
|
|
</span>
|
|
<span class="text-xs text-muted">{{ teammate.role }}</span>
|
|
</div>
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<template #empty>
|
|
<EmptyState>未找到团队成员</EmptyState>
|
|
</template>
|
|
</ListBox>
|
|
</AutocompleteFilter>
|
|
</AutocompletePopover>
|
|
</Autocomplete>
|
|
</div>
|
|
</template>
|