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.
87 lines
2.2 KiB
Vue
87 lines
2.2 KiB
Vue
<script setup lang="ts">
|
||
import { computed, ref } from "vue";
|
||
import {
|
||
Autocomplete,
|
||
AutocompleteClearButton,
|
||
AutocompleteFilter,
|
||
AutocompleteIndicator,
|
||
AutocompletePopover,
|
||
AutocompleteTrigger,
|
||
AutocompleteValue,
|
||
EmptyState,
|
||
Label,
|
||
ListBox,
|
||
ListBoxItem,
|
||
ListBoxItemIndicator,
|
||
SearchField,
|
||
SearchFieldClearButton,
|
||
SearchFieldGroup,
|
||
SearchFieldInput,
|
||
SearchFieldSearchIcon,
|
||
} from "@heroui-vue/components";
|
||
|
||
const states = [
|
||
{ id: "california", name: "California" },
|
||
{ id: "texas", name: "Texas" },
|
||
{ id: "florida", name: "Florida" },
|
||
{ id: "new-york", name: "New York" },
|
||
{ id: "illinois", name: "Illinois" },
|
||
{ id: "pennsylvania", name: "Pennsylvania" },
|
||
];
|
||
|
||
const state = ref<string | null>("california");
|
||
|
||
const selectedState = computed(() =>
|
||
states.find((item) => item.id === state.value),
|
||
);
|
||
</script>
|
||
|
||
<template>
|
||
<div class="space-y-2">
|
||
<Autocomplete
|
||
v-model="state"
|
||
class="w-[256px]"
|
||
placeholder="选择一个州"
|
||
selection-mode="single"
|
||
>
|
||
<Label>州(受控)</Label>
|
||
<AutocompleteTrigger>
|
||
<AutocompleteValue />
|
||
<AutocompleteClearButton />
|
||
<AutocompleteIndicator />
|
||
</AutocompleteTrigger>
|
||
<AutocompletePopover>
|
||
<AutocompleteFilter>
|
||
<SearchField
|
||
auto-focus
|
||
name="search"
|
||
variant="secondary"
|
||
aria-label="搜索州名"
|
||
>
|
||
<SearchFieldGroup>
|
||
<SearchFieldSearchIcon />
|
||
<SearchFieldInput placeholder="搜索州名…" />
|
||
<SearchFieldClearButton />
|
||
</SearchFieldGroup>
|
||
</SearchField>
|
||
<ListBox>
|
||
<ListBoxItem
|
||
v-for="item in states"
|
||
:id="item.id"
|
||
:key="item.id"
|
||
:text-value="item.name"
|
||
>
|
||
{{ item.name }}
|
||
<ListBoxItemIndicator />
|
||
</ListBoxItem>
|
||
<template #empty>
|
||
<EmptyState>未找到结果</EmptyState>
|
||
</template>
|
||
</ListBox>
|
||
</AutocompleteFilter>
|
||
</AutocompletePopover>
|
||
</Autocomplete>
|
||
<p class="text-sm text-muted">已选:{{ selectedState?.name || "无" }}</p>
|
||
</div>
|
||
</template>
|