Files
heroui-vue/apps/docs/demos/combo-box-form-value.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

87 lines
2.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import {
Button,
ComboBox,
ComboBoxInputGroup,
ComboBoxPopover,
ComboBoxTrigger,
Description,
FieldError,
Form,
Input,
Label,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
} from "@heroui-vue/components";
import { ref } from "vue";
const animals = [
{ id: "aardvark", name: "土豚" },
{ id: "cat", name: "猫" },
{ id: "dog", name: "狗" },
{ id: "kangaroo", name: "袋鼠" },
{ id: "panda", name: "熊猫" },
{ id: "snake", name: "蛇" },
];
const message = ref<string | null>(null);
function onSubmit(event: Event) {
event.preventDefault();
const formData = new FormData(event.currentTarget as HTMLFormElement);
message.value = `key:${formData.get("animal")}。文本:${formData.get("animal-text")}。`;
}
</script>
<template>
<Form class="flex w-[256px] flex-col gap-4" @submit="onSubmit">
<ComboBox is-required class="w-full" form-value="key" name="animal">
<Label>动物</Label>
<ComboBoxInputGroup>
<Input placeholder="选择动物…" />
<ComboBoxTrigger />
</ComboBoxInputGroup>
<ComboBoxPopover>
<ListBox>
<ListBoxItem
v-for="animal in animals"
:id="animal.id"
:key="animal.id"
:text-value="animal.name"
>
{{ animal.name }}
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</ComboBoxPopover>
<Description>提交选中项的 key</Description>
<FieldError />
</ComboBox>
<ComboBox is-required class="w-full" form-value="text" name="animal-text">
<Label>动物(文本)</Label>
<ComboBoxInputGroup>
<Input placeholder="选择动物…" />
<ComboBoxTrigger />
</ComboBoxInputGroup>
<ComboBoxPopover>
<ListBox>
<ListBoxItem
v-for="animal in animals"
:id="animal.id"
:key="animal.id"
:text-value="animal.name"
>
{{ animal.name }}
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</ComboBoxPopover>
<Description>提交选中项的文本</Description>
<FieldError />
</ComboBox>
<Button class="w-fit" type="submit">提交</Button>
<p v-if="message" class="text-sm text-muted" role="status">{{ message }}</p>
</Form>
</template>