Files
heroui-vue/apps/docs/demos/combo-box-with-sections.vue
maoyingjie 46e4df7e85 feat(combo-box): migrate ComboBox with input-owned focus and filtering
Port the fixed-baseline ComboBox onto the B02a collection protocol: the input
keeps real DOM focus, the list only tracks an active row, and filtering reuses
the owner filter instead of a second collection kernel.

- Five parts: root (field text control, value/input/open models, form value,
  owner wiring), InputGroup (composes the caller's Input into the combobox
  control and anchors the popover), Trigger, Value, Popover.
- Closed-state metadata is planned from the slot tree, so filtering, the initial
  value label and form-value="text" work before the list has mounted.
- Selection text syncs on selection changes only, so allows-custom-value typing
  is not overwritten; read-only and disabled are injected onto the composed
  input because it reads the text-field protocol, not the field context.
- 24 baseline previews, the Chinese doc page, navigation, 19 behaviour tests and
  6 demo/document contracts. Async demo uses a local async source with abort,
  loading and incremental append (documented adaptations).

Not included: independent tarball consumption (B02d).
2026-10-25 16:59:16 +08:00

90 lines
2.5 KiB
Vue

<script setup lang="ts">
import {
ComboBox,
ComboBoxInputGroup,
ComboBoxPopover,
ComboBoxTrigger,
Header,
Input,
Label,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
ListBoxSection,
Separator,
} from "@heroui-vue/components";
</script>
<template>
<ComboBox class="w-[256px]">
<Label>国家</Label>
<ComboBoxInputGroup>
<Input placeholder="搜索国家…" />
<ComboBoxTrigger />
</ComboBoxInputGroup>
<ComboBoxPopover>
<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>
</ListBox>
</ComboBoxPopover>
</ComboBox>
</template>