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

112 lines
2.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 {
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 nativeMessage = ref<string | null>(null);
const ariaMessage = ref<string | null>(null);
function submitNative(event: Event) {
event.preventDefault();
nativeMessage.value = "已通过原生校验提交。";
}
function submitAria(event: Event) {
event.preventDefault();
ariaMessage.value = "已通过 ARIA 校验提交。";
}
</script>
<template>
<div class="flex flex-col gap-8">
<Form class="flex w-[256px] flex-col gap-4" @submit="submitNative">
<ComboBox
is-required
class="w-full"
name="animal"
validation-behavior="native"
>
<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="nativeMessage" class="text-sm text-muted" role="status">
{{ nativeMessage }}
</p>
</Form>
<Form class="flex w-[256px] flex-col gap-4" @submit="submitAria">
<ComboBox
is-required
class="w-full"
name="animal-aria"
validation-behavior="aria"
>
<Label>动物(ARIA 校验)</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="ariaMessage" class="text-sm text-muted" role="status">
{{ ariaMessage }}
</p>
</Form>
</div>
</template>