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.
104 lines
2.6 KiB
Vue
104 lines
2.6 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from "vue";
|
|
import {
|
|
Autocomplete,
|
|
AutocompleteFilter,
|
|
AutocompleteIndicator,
|
|
AutocompletePopover,
|
|
AutocompleteTrigger,
|
|
AutocompleteValue,
|
|
EmptyState,
|
|
Label,
|
|
ListBox,
|
|
ListBoxItem,
|
|
ListBoxItemIndicator,
|
|
SearchField,
|
|
SearchFieldClearButton,
|
|
SearchFieldGroup,
|
|
SearchFieldInput,
|
|
SearchFieldSearchIcon,
|
|
Tag,
|
|
TagGroup,
|
|
TagGroupList,
|
|
type TagKey,
|
|
} from "@heroui-vue/components";
|
|
|
|
const states = [
|
|
{ id: "florida", name: "Florida" },
|
|
{ id: "delaware", name: "Delaware" },
|
|
{ id: "california", name: "California" },
|
|
{ id: "texas", name: "Texas" },
|
|
{ id: "new-york", name: "New York" },
|
|
{ id: "washington", name: "Washington" },
|
|
];
|
|
|
|
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>
|
|
<AutocompleteIndicator />
|
|
</AutocompleteTrigger>
|
|
<AutocompletePopover>
|
|
<AutocompleteFilter>
|
|
<SearchField
|
|
auto-focus
|
|
name="search"
|
|
variant="secondary"
|
|
aria-label="搜索选项"
|
|
>
|
|
<SearchFieldGroup>
|
|
<SearchFieldSearchIcon />
|
|
<SearchFieldInput placeholder="搜索…" />
|
|
<SearchFieldClearButton />
|
|
</SearchFieldGroup>
|
|
</SearchField>
|
|
<ListBox>
|
|
<ListBoxItem
|
|
v-for="state in states"
|
|
:id="state.id"
|
|
:key="state.id"
|
|
:text-value="state.name"
|
|
>
|
|
{{ state.name }}
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<template #empty>
|
|
<EmptyState>未找到结果</EmptyState>
|
|
</template>
|
|
</ListBox>
|
|
</AutocompleteFilter>
|
|
</AutocompletePopover>
|
|
</Autocomplete>
|
|
</template>
|