Files
heroui-vue/apps/docs/demos/autocomplete-with-sections.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

124 lines
3.5 KiB
Vue

<script setup lang="ts">
import { ref } from "vue";
import {
Autocomplete,
AutocompleteClearButton,
AutocompleteFilter,
AutocompleteIndicator,
AutocompletePopover,
AutocompleteTrigger,
AutocompleteValue,
EmptyState,
Header,
Label,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
ListBoxSection,
SearchField,
SearchFieldClearButton,
SearchFieldGroup,
SearchFieldInput,
SearchFieldSearchIcon,
Separator,
} from "@heroui-vue/components";
const selectedKey = ref<string | null>(null);
</script>
<template>
<Autocomplete
v-model="selectedKey"
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>
<ListBoxSection>
<Header>北美洲</Header>
<ListBoxItem id="usa" text-value="美国">
美国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="canada" text-value="加拿大">
加拿大
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="mexico" text-value="墨西哥">
墨西哥
<ListBoxItemIndicator />
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>欧洲</Header>
<ListBoxItem id="uk" text-value="英国">
英国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="france" text-value="法国">
法国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="germany" text-value="德国">
德国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="spain" text-value="西班牙">
西班牙
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="italy" text-value="意大利">
意大利
<ListBoxItemIndicator />
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>亚洲</Header>
<ListBoxItem id="japan" text-value="日本">
日本
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="china" text-value="中国">
中国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="india" text-value="印度">
印度
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="south-korea" text-value="韩国">
韩国
<ListBoxItemIndicator />
</ListBoxItem>
</ListBoxSection>
<template #empty>
<EmptyState>未找到结果</EmptyState>
</template>
</ListBox>
</AutocompleteFilter>
</AutocompletePopover>
</Autocomplete>
</template>