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

71 lines
1.9 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 { ref } from "vue";
import {
Button,
ComboBox,
ComboBoxInputGroup,
ComboBoxPopover,
ComboBoxTrigger,
FieldError,
Form,
Input,
Label,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
} from "@heroui-vue/components";
const submitted = ref(false);
function submit(event: Event) {
// The Form guard already blocks invalid submits, so a reached handler is valid.
void new FormData(event.currentTarget as HTMLFormElement);
submitted.value = true;
}
</script>
<template>
<Form class="flex w-[256px] flex-col gap-4" @submit.prevent="submit">
<ComboBox is-required class="w-full" name="animal">
<Label>最喜欢的动物</Label>
<ComboBoxInputGroup>
<Input placeholder="搜索动物…" />
<ComboBoxTrigger />
</ComboBoxInputGroup>
<ComboBoxPopover>
<ListBox>
<ListBoxItem id="aardvark" text-value="土豚">
土豚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="cat" text-value="猫">
猫
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="dog" text-value="狗">
狗
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="kangaroo" text-value="袋鼠">
袋鼠
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="panda" text-value="熊猫">
熊猫
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="snake" text-value="蛇">
蛇
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</ComboBoxPopover>
<FieldError />
</ComboBox>
<Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-muted">
表单提交成功!
</p>
</Form>
</template>