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.
99 lines
2.8 KiB
Vue
99 lines
2.8 KiB
Vue
<script setup lang="ts">
|
|
import {
|
|
Autocomplete,
|
|
AutocompleteFilter,
|
|
AutocompleteIndicator,
|
|
AutocompletePopover,
|
|
AutocompleteTrigger,
|
|
AutocompleteValue,
|
|
Description,
|
|
EmptyState,
|
|
Label,
|
|
ListBox,
|
|
ListBoxItem,
|
|
ListBoxItemIndicator,
|
|
SearchField,
|
|
SearchFieldClearButton,
|
|
SearchFieldGroup,
|
|
SearchFieldInput,
|
|
SearchFieldSearchIcon,
|
|
} from "@heroui-vue/components";
|
|
|
|
const currencies = [
|
|
{ code: "USD", id: "usd", name: "美元", symbol: "$" },
|
|
{ code: "EUR", id: "eur", name: "欧元", symbol: "€" },
|
|
{ code: "GBP", id: "gbp", name: "英镑", symbol: "£" },
|
|
{ code: "JPY", id: "jpy", name: "日元", symbol: "¥" },
|
|
{ code: "CHF", id: "chf", name: "瑞士法郎", symbol: "₣" },
|
|
];
|
|
|
|
const currencyOf = (key: unknown) =>
|
|
currencies.find((currency) => currency.id === key);
|
|
</script>
|
|
|
|
<template>
|
|
<Autocomplete
|
|
class="w-[256px]"
|
|
default-value="usd"
|
|
placeholder="选择货币"
|
|
selection-mode="single"
|
|
>
|
|
<Label>货币</Label>
|
|
<AutocompleteTrigger>
|
|
<AutocompleteValue>
|
|
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
|
<span
|
|
v-if="isPlaceholder || !currencyOf(selectedItems[0]?.key)"
|
|
class="flex min-w-0 items-center gap-1.5"
|
|
>
|
|
{{ defaultChildren }}
|
|
</span>
|
|
<span v-else class="flex min-w-0 items-center gap-1.5">
|
|
<span class="font-medium">
|
|
{{ currencyOf(selectedItems[0]?.key)?.symbol }}
|
|
</span>
|
|
<span>{{ currencyOf(selectedItems[0]?.key)?.code }}</span>
|
|
<span class="truncate text-muted">
|
|
{{ currencyOf(selectedItems[0]?.key)?.name }}
|
|
</span>
|
|
</span>
|
|
</template>
|
|
</AutocompleteValue>
|
|
<AutocompleteIndicator />
|
|
</AutocompleteTrigger>
|
|
<AutocompletePopover>
|
|
<AutocompleteFilter>
|
|
<SearchField
|
|
auto-focus
|
|
aria-label="搜索货币"
|
|
name="search"
|
|
variant="secondary"
|
|
>
|
|
<SearchFieldGroup>
|
|
<SearchFieldSearchIcon />
|
|
<SearchFieldInput placeholder="搜索货币…" />
|
|
<SearchFieldClearButton />
|
|
</SearchFieldGroup>
|
|
</SearchField>
|
|
<ListBox>
|
|
<ListBoxItem
|
|
v-for="currency in currencies"
|
|
:id="currency.id"
|
|
:key="currency.id"
|
|
:text-value="`${currency.code} ${currency.name}`"
|
|
>
|
|
<div class="flex flex-col">
|
|
<Label>{{ currency.code }}</Label>
|
|
<Description>{{ currency.name }}</Description>
|
|
</div>
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<template #empty>
|
|
<EmptyState>未找到结果</EmptyState>
|
|
</template>
|
|
</ListBox>
|
|
</AutocompleteFilter>
|
|
</AutocompletePopover>
|
|
</Autocomplete>
|
|
</template>
|