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.
152 lines
4.0 KiB
Vue
152 lines
4.0 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from "vue";
|
|
import {
|
|
Autocomplete,
|
|
AutocompleteClearButton,
|
|
AutocompleteFilter,
|
|
AutocompleteIndicator,
|
|
AutocompletePopover,
|
|
AutocompleteTrigger,
|
|
AutocompleteValue,
|
|
Button,
|
|
EmptyState,
|
|
FieldError,
|
|
Form,
|
|
Label,
|
|
ListBox,
|
|
ListBoxItem,
|
|
ListBoxItemIndicator,
|
|
SearchField,
|
|
SearchFieldClearButton,
|
|
SearchFieldGroup,
|
|
SearchFieldInput,
|
|
SearchFieldSearchIcon,
|
|
} 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 countries = [
|
|
{ id: "usa", name: "United States" },
|
|
{ id: "canada", name: "Canada" },
|
|
{ id: "mexico", name: "Mexico" },
|
|
{ id: "uk", name: "United Kingdom" },
|
|
{ id: "france", name: "France" },
|
|
{ id: "germany", name: "Germany" },
|
|
];
|
|
|
|
const message = ref<string | null>(null);
|
|
|
|
function onSubmit(event: Event) {
|
|
event.preventDefault();
|
|
const formData = new FormData(event.currentTarget as HTMLFormElement);
|
|
void formData;
|
|
message.value = "表单提交成功!";
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<Form class="flex w-[256px] flex-col gap-4" @submit="onSubmit">
|
|
<Autocomplete
|
|
is-required
|
|
class="w-full"
|
|
name="state"
|
|
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="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>
|
|
<FieldError />
|
|
</Autocomplete>
|
|
<Autocomplete
|
|
is-required
|
|
class="w-full"
|
|
name="country"
|
|
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="country in countries"
|
|
:id="country.id"
|
|
:key="country.id"
|
|
:text-value="country.name"
|
|
>
|
|
{{ country.name }}
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
<template #empty>
|
|
<EmptyState>未找到结果</EmptyState>
|
|
</template>
|
|
</ListBox>
|
|
</AutocompleteFilter>
|
|
</AutocompletePopover>
|
|
<FieldError />
|
|
</Autocomplete>
|
|
<Button type="submit">提交</Button>
|
|
<p v-if="message" role="status" class="text-sm text-muted">
|
|
{{ message }}
|
|
</p>
|
|
</Form>
|
|
</template>
|