feat(collections): auto incremental async loading, shared filtering and submenu delay

HD-10 scope, against heroui ce90ea3 collection sources and their
react-aria/react-stately dependencies:

- the ComboBox async demo now auto-loads on scroll-to-bottom
  (IntersectionObserver sentinel + fill chain mirroring the pinned
  ListBoxLoadMoreItem re-observe semantics), never duplicates requests
  (loading guards + monotonic sequence token), drops stale responses on
  query switches, keeps a retry path for failures (injectable mock
  failure) and documents its differences from the pinned SWAPI source;
  the Select demo's observer stays untouched (real-network scroll
  triggering verified in browser)
- the Autocomplete virtualization demo and the default filter share one
  locale-sensitive matcher: createBaseContains (Intl.Collator base
  sensitivity, cafe matches Cafe with accent folding) is now exported
  from the package root
- Autocomplete trigger semantics verified complete (single tab stop,
  Enter/Space/Escape/Delete/IME, single and multiple selection) and the
  scoped slots gained composition data instead of child copying:
  AutocompleteValue exposes selectedItem and per-entry source item,
  the ComboBox root exposes selectedItem
- DropdownSubmenuTrigger exposes the pinned delay contract (default
  200ms): the controlled open gate retimes Reka's fixed 100ms hover,
  keyboard opens stay immediate and cancel the pending hover, pointer
  leave cancels; the dead side/align forwarding is gone (Reka fixes the
  submenu side per direction); Button/Avatar trigger layout
  compensation kept after browser proof it is what wins the cascade
- tests/fixtures/collections-rtl.vue drives the real-browser delay and
  RTL geometry checks; b02-pickers contract pins the new export and
  slot typing

Full suite 111 files / 1666 tests, typecheck, build:docs and the
b02-pickers + api-root-aliases tarball contracts pass.
This commit is contained in:
maoyingjie
2026-10-29 13:46:13 +08:00
parent c34faccd70
commit c8d54abefb
21 changed files with 1020 additions and 173 deletions
+110
View File
@@ -1316,3 +1316,113 @@ it("menu-level close policy wins over the section mode default", async () => {
await nextTick();
expect(document.querySelector('[data-slot="menu-item"]')).not.toBeNull();
});
function mountSubmenuWithDelay(delay?: number) {
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true }, () => [
h(DropdownTrigger, {}, () => h(Button, () => "菜单")),
h(DropdownPopover, {}, () =>
h(DropdownMenu, {}, () => [
h(DropdownSubmenuTrigger, { delay }, () => [
h(DropdownItem, { id: "share", textValue: "分享" }, () => [
h(Label, () => "分享"),
h(DropdownSubmenuIndicator),
]),
h(DropdownPopover, {}, () =>
h(DropdownMenu, {}, () =>
h(
DropdownItem,
{ id: "whatsapp", textValue: "WhatsApp" },
() => h(Label, () => "WhatsApp"),
),
),
),
]),
]),
),
]),
);
}
function hoverMove(node: Element) {
node.dispatchEvent(pointer("pointermove", { pointerType: "mouse" }));
}
function subContent() {
return document.querySelector("[data-submenu-content]");
}
it("submenu hover opens after the baseline delay (200ms), not Reka's fixed 100ms", async () => {
vi.useFakeTimers();
mountSubmenuWithDelay();
await flushPromises();
await nextTick();
const trigger = document.querySelector(
'[data-slot="menu-item"][data-has-submenu="true"]',
) as HTMLElement;
hoverMove(trigger);
// Reka's own 100ms timer requests the open; the configured delay defers it.
await vi.advanceTimersByTimeAsync(150);
await nextTick();
expect(subContent()).toBeNull();
await vi.advanceTimersByTimeAsync(100);
await nextTick();
expect(subContent()).toBeTruthy();
vi.useRealTimers();
});
it("submenu hover honors a custom delay and pointer leave cancels it", async () => {
vi.useFakeTimers();
mountSubmenuWithDelay(600);
await flushPromises();
await nextTick();
const trigger = document.querySelector(
'[data-slot="menu-item"][data-has-submenu="true"]',
) as HTMLElement;
hoverMove(trigger);
await vi.advanceTimersByTimeAsync(400);
await nextTick();
expect(subContent()).toBeNull();
trigger.dispatchEvent(pointer("pointerleave", { pointerType: "mouse" }));
await vi.advanceTimersByTimeAsync(500);
await nextTick();
expect(subContent()).toBeNull();
// A fresh hover re-arms the full delay.
hoverMove(trigger);
await vi.advanceTimersByTimeAsync(300);
await nextTick();
expect(subContent()).toBeNull();
await vi.advanceTimersByTimeAsync(350);
await nextTick();
expect(subContent()).toBeTruthy();
vi.useRealTimers();
});
it("keyboard submenu open is immediate and cancels the pending hover open", async () => {
vi.useFakeTimers();
mountSubmenuWithDelay();
await flushPromises();
await nextTick();
const trigger = document.querySelector(
'[data-slot="menu-item"][data-has-submenu="true"]',
) as HTMLElement;
hoverMove(trigger);
await vi.advanceTimersByTimeAsync(50);
trigger.focus();
trigger.dispatchEvent(
new KeyboardEvent("keydown", {
key: "ArrowRight",
bubbles: true,
cancelable: true,
}),
);
await flushPromises();
await nextTick();
expect(subContent()).toBeTruthy();
// The cancelled hover timer must not produce a second open request later.
await vi.advanceTimersByTimeAsync(400);
await nextTick();
expect(subContent()).toBeTruthy();
vi.useRealTimers();
});
+110
View File
@@ -218,3 +218,113 @@ describe("ComboBox docs and demos", () => {
mounted.pop();
});
});
describe("asynchronous loading demo", () => {
class FakeIntersectionObserver {
static instances: FakeIntersectionObserver[] = [];
callback: (entries: unknown[]) => void;
constructor(callback: (entries: unknown[]) => void) {
this.callback = callback;
FakeIntersectionObserver.instances.push(this);
}
observe() {}
unobserve() {}
disconnect() {}
trigger(isIntersecting: boolean) {
this.callback([{ isIntersecting }]);
}
static last() {
return FakeIntersectionObserver.instances.at(-1)!;
}
static reset() {
FakeIntersectionObserver.instances = [];
}
}
async function mountAsyncDemo() {
vi.useFakeTimers();
vi.stubGlobal("IntersectionObserver", FakeIntersectionObserver);
FakeIntersectionObserver.reset();
const demo = (
await import("../apps/docs/demos/combo-box-asynchronous-loading.vue")
).default;
const w = mount(demo, { attachTo: document.body });
mounted.push(w);
// Initial page resolves on the simulated latency.
await vi.advanceTimersByTimeAsync(350);
await nextTick();
(w.get('[data-slot="input"]').element as HTMLInputElement).focus();
await nextTick();
return w;
}
const optionNames = () =>
[...document.querySelectorAll('[role="option"]')].map((node) =>
node.textContent?.trim(),
);
afterEach(() => {
vi.useRealTimers();
vi.unstubAllGlobals();
FakeIntersectionObserver.reset();
});
it("auto-loads the next page when the sentinel intersects, without duplicate requests", async () => {
const w = await mountAsyncDemo();
expect(optionNames()).toHaveLength(4);
// Two intersections in the same tick must start one request only: a
// duplicated fetch would append the same offset twice.
FakeIntersectionObserver.last().trigger(true);
FakeIntersectionObserver.last().trigger(true);
await vi.advanceTimersByTimeAsync(350);
await nextTick();
const afterFirst = optionNames();
expect(afterFirst).toHaveLength(8);
expect(new Set(afterFirst).size).toBe(8);
// The chain fills the remaining page while the sentinel stays visible.
await vi.advanceTimersByTimeAsync(350);
await nextTick();
expect(optionNames()).toHaveLength(12);
expect(document.body.textContent).not.toContain("加载更多…");
void w;
});
it("drops stale responses when the query switches mid-flight", async () => {
await mountAsyncDemo();
const input = document.querySelector<HTMLInputElement>(
'[data-slot="input"]',
)!;
input.value = "vader";
input.dispatchEvent(new Event("input", { bubbles: true }));
await vi.advanceTimersByTimeAsync(100);
input.value = "solo";
input.dispatchEvent(new Event("input", { bubbles: true }));
await vi.advanceTimersByTimeAsync(800);
await nextTick();
const names = optionNames();
expect(names).toEqual(["Han Solo"]);
});
it("retries a failed page from the error state", async () => {
const w = await mountAsyncDemo();
const checkbox = w.get('input[type="checkbox"]');
await checkbox.setValue(true);
FakeIntersectionObserver.last().trigger(true);
await vi.advanceTimersByTimeAsync(350);
await nextTick();
// The error row renders inside the teleported popover surface.
expect(document.body.textContent).toContain("重试");
expect(optionNames()).toHaveLength(4);
await checkbox.setValue(false);
const retry = [...document.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "重试",
)!;
expect(retry).toBeTruthy();
retry.click();
await vi.advanceTimersByTimeAsync(350);
await nextTick();
expect(document.body.textContent).not.toContain("重试");
expect(optionNames()).toHaveLength(8);
void w;
});
});
+88
View File
@@ -0,0 +1,88 @@
<script setup lang="ts">
import { computed, defineComponent, h, ref } from "vue";
import {
Button,
ConfigProvider,
DropdownItem,
DropdownMenu,
DropdownPopover,
DropdownRoot,
DropdownSubmenuIndicator,
DropdownSubmenuTrigger,
DropdownTrigger,
Label,
useLocale,
} from "@heroui-vue/components";
/**
* HD-10 submenu verification harness: the pinned RTL behaviour (submenu flips
* to the left of its trigger) and the configurable hover delay, driven through
* the public ConfigProvider direction contract.
*/
const rtl = ref(true);
const opened = ref(0);
const localeDir = useLocale().dir;
const probe = computed(() => `outer-dir=${localeDir.value}`);
const InnerProbe = defineComponent({
setup() {
const dir = useLocale().dir;
return () =>
h("output", { "data-probe-inner": "" }, `inner-dir=${dir.value}`);
},
});
</script>
<template>
<main style="padding: 24px; display: grid; gap: 16px; justify-items: center">
<label>
<input v-model="rtl" type="checkbox" />
RTL(ConfigProvider dir)
</label>
<output data-probe>{{ probe }}</output>
<ConfigProvider :dir="rtl ? 'rtl' : 'ltr'">
<InnerProbe />
<div style="width: 700px; display: flex; justify-content: center">
<DropdownRoot :dir="rtl ? 'rtl' : 'ltr'" @open-change="opened++">
<DropdownTrigger>
<Button aria-label="菜单">菜单</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu aria-label="示例菜单">
<DropdownItem id="copy" text-value="复制">
<Label>复制</Label>
</DropdownItem>
<!-- Baseline default delay: 200ms. -->
<DropdownSubmenuTrigger>
<DropdownItem id="share" text-value="分享">
<Label>分享(默认延迟)</Label>
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu aria-label="分享">
<DropdownItem id="mail" text-value="邮件">
<Label>邮件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
<!-- Custom delay: 600ms. -->
<DropdownSubmenuTrigger :delay="600">
<DropdownItem id="more" text-value="更多">
<Label>更多(600ms 延迟)</Label>
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu aria-label="更多">
<DropdownItem id="report" text-value="举报">
<Label>举报</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</div>
</ConfigProvider>
</main>
</template>
+8 -1
View File
@@ -14,6 +14,7 @@ import {
ComboBoxValue,
ListBox,
ListBoxItem,
createBaseContains,
type AutocompleteItem,
type AutocompleteProps,
type AutocompleteState,
@@ -152,8 +153,11 @@ const badComboEvent = h(ComboBox, {
});
// Root scoped slots expose the open/selection state.
const sharedMatcher: (text: string, query: string) => boolean =
createBaseContains("zh-CN");
void sharedMatcher("Café", "cafe");
const comboState = (state: ComboBoxState): string =>
`${state.isOpen}:${state.inputValue}:${state.selectedKeys.length}`;
`${state.isOpen}:${state.inputValue}:${state.selectedKeys.length}:${state.selectedItem?.textValue ?? ""}`;
const autocompleteState = (state: AutocompleteState): string =>
`${state.isOpen}:${state.selectedKeys.length}`;
const comboValueState = (state: ComboBoxValueState): string =>
@@ -191,6 +195,9 @@ const autocompleteTree = h(Autocomplete, { "aria-label": "州" }, () => [
const placeholder: boolean = state.isPlaceholder;
const joined: string = state.selectedText || state.defaultChildren;
const keys = state.selectedItems.map((item) => item.key);
// Source `items` data rides along for rich trigger composition.
const source = state.selectedItem?.item?.textValue ?? "";
void source;
return placeholder ? joined : keys.join(",");
},
}),
+358 -90
View File
@@ -80,7 +80,8 @@
"AutocompletePopover",
"AutocompleteFilter",
"comboBoxVariants",
"autocompleteVariants"
"autocompleteVariants",
"createBaseContains"
],
"css": [
".hv-combo-box",
@@ -169,7 +170,9 @@
]
},
"color-field-protocol": {
"exports": ["ColorPicker"],
"exports": [
"ColorPicker"
],
"css": [
".hv-color-field",
".hv-color-input-group",
@@ -180,8 +183,13 @@
]
},
"color-foundation": {
"exports": ["ColorPicker"],
"css": [".hv-color-area", ".hv-color-area__thumb"]
"exports": [
"ColorPicker"
],
"css": [
".hv-color-area",
".hv-color-area__thumb"
]
},
"color-picker-protocol": {
"exports": [
@@ -198,7 +206,9 @@
]
},
"color-slider-foundation": {
"exports": ["ColorPicker"],
"exports": [
"ColorPicker"
],
"css": [
".hv-color-slider",
".hv-color-slider__track",
@@ -290,7 +300,11 @@
"PaginationItem",
"PaginationLink"
],
"css": ["hv-header", "hv-pagination", "hv-input-otp"]
"css": [
"hv-header",
"hv-pagination",
"hv-input-otp"
]
},
"m33-m34": {
"exports": [
@@ -402,7 +416,10 @@
"Label",
"sliderVariants"
],
"css": [".hv-slider__track", "hv-slider__thumb"]
"css": [
".hv-slider__track",
"hv-slider__thumb"
]
},
"color-swatch": {
"exports": [
@@ -607,7 +624,12 @@
"FieldError",
"Button"
],
"css": [".hv-textfield", ".hv-input", ".hv-field-error", ".hv-button"]
"css": [
".hv-textfield",
".hv-input",
".hv-field-error",
".hv-button"
]
},
"api-root-aliases": {
"exports": [
@@ -778,88 +800,334 @@
"TypographyRoot"
],
"aliases": [
["Accordion", "AccordionRoot"],
["Alert", "AlertRoot"],
["AlertDialog", "AlertDialogRoot"],
["Autocomplete", "AutocompleteRoot"],
["Avatar", "AvatarRoot"],
["AvatarGroup", "AvatarGroupRoot"],
["Badge", "BadgeRoot"],
["Breadcrumbs", "BreadcrumbsRoot"],
["Button", "ButtonRoot"],
["ButtonGroup", "ButtonGroupRoot"],
["Calendar", "CalendarRoot"],
["Card", "CardRoot"],
["Checkbox", "CheckboxRoot"],
["Chip", "ChipRoot"],
["CloseButton", "CloseButtonRoot"],
["ColorArea", "ColorAreaRoot"],
["ColorField", "ColorFieldRoot"],
["ColorInputGroup", "ColorInputGroupRoot"],
["ColorPicker", "ColorPickerRoot"],
["ColorSlider", "ColorSliderRoot"],
["ColorSwatch", "ColorSwatchRoot"],
["ColorSwatchPicker", "ColorSwatchPickerRoot"],
["ComboBox", "ComboBoxRoot"],
["DateField", "DateFieldRoot"],
["DateInputGroup", "DateInputGroupRoot"],
["DatePicker", "DatePickerRoot"],
["DateRangePicker", "DateRangePickerRoot"],
["Description", "DescriptionRoot"],
["Disclosure", "DisclosureRoot"],
["DisclosureGroup", "DisclosureGroupRoot"],
["Drawer", "DrawerRoot"],
["Dropdown", "DropdownRoot"],
["EmptyState", "EmptyStateRoot"],
["ErrorMessage", "ErrorMessageRoot"],
["FieldError", "FieldErrorRoot"],
["Fieldset", "FieldsetRoot"],
["Form", "FormRoot"],
["Header", "HeaderRoot"],
["Input", "InputRoot"],
["InputGroup", "InputGroupRoot"],
["InputOTP", "InputOTPRoot"],
["Kbd", "KbdRoot"],
["Label", "LabelRoot"],
["Link", "LinkRoot"],
["ListBox", "ListBoxRoot"],
["ListBoxItem", "ListBoxItemRoot"],
["ListBoxSection", "ListBoxSectionRoot"],
["Menu", "MenuRoot"],
["MenuItem", "MenuItemRoot"],
["MenuSection", "MenuSectionRoot"],
["Meter", "MeterRoot"],
["Modal", "ModalRoot"],
["NumberField", "NumberFieldRoot"],
["Pagination", "PaginationRoot"],
["Popover", "PopoverRoot"],
["ProgressBar", "ProgressBarRoot"],
["ProgressCircle", "ProgressCircleRoot"],
["Radio", "RadioRoot"],
["RadioGroup", "RadioGroupRoot"],
["RangeCalendar", "RangeCalendarRoot"],
["ScrollShadow", "ScrollShadowRoot"],
["SearchField", "SearchFieldRoot"],
["Select", "SelectRoot"],
["Separator", "SeparatorRoot"],
["Skeleton", "SkeletonRoot"],
["Slider", "SliderRoot"],
["Spinner", "SpinnerRoot"],
["Surface", "SurfaceRoot"],
["Switch", "SwitchRoot"],
["SwitchGroup", "SwitchGroupRoot"],
["Table", "TableRoot"],
["Tabs", "TabsRoot"],
["Tag", "TagRoot"],
["TagGroup", "TagGroupRoot"],
["TextArea", "TextAreaRoot"],
["TextField", "TextFieldRoot"],
["TimeField", "TimeFieldRoot"],
["ToggleButton", "ToggleButtonRoot"],
["ToggleButtonGroup", "ToggleButtonGroupRoot"],
["Toolbar", "ToolbarRoot"],
["Tooltip", "TooltipRoot"],
["Typography", "TypographyRoot"]
[
"Accordion",
"AccordionRoot"
],
[
"Alert",
"AlertRoot"
],
[
"AlertDialog",
"AlertDialogRoot"
],
[
"Autocomplete",
"AutocompleteRoot"
],
[
"Avatar",
"AvatarRoot"
],
[
"AvatarGroup",
"AvatarGroupRoot"
],
[
"Badge",
"BadgeRoot"
],
[
"Breadcrumbs",
"BreadcrumbsRoot"
],
[
"Button",
"ButtonRoot"
],
[
"ButtonGroup",
"ButtonGroupRoot"
],
[
"Calendar",
"CalendarRoot"
],
[
"Card",
"CardRoot"
],
[
"Checkbox",
"CheckboxRoot"
],
[
"Chip",
"ChipRoot"
],
[
"CloseButton",
"CloseButtonRoot"
],
[
"ColorArea",
"ColorAreaRoot"
],
[
"ColorField",
"ColorFieldRoot"
],
[
"ColorInputGroup",
"ColorInputGroupRoot"
],
[
"ColorPicker",
"ColorPickerRoot"
],
[
"ColorSlider",
"ColorSliderRoot"
],
[
"ColorSwatch",
"ColorSwatchRoot"
],
[
"ColorSwatchPicker",
"ColorSwatchPickerRoot"
],
[
"ComboBox",
"ComboBoxRoot"
],
[
"DateField",
"DateFieldRoot"
],
[
"DateInputGroup",
"DateInputGroupRoot"
],
[
"DatePicker",
"DatePickerRoot"
],
[
"DateRangePicker",
"DateRangePickerRoot"
],
[
"Description",
"DescriptionRoot"
],
[
"Disclosure",
"DisclosureRoot"
],
[
"DisclosureGroup",
"DisclosureGroupRoot"
],
[
"Drawer",
"DrawerRoot"
],
[
"Dropdown",
"DropdownRoot"
],
[
"EmptyState",
"EmptyStateRoot"
],
[
"ErrorMessage",
"ErrorMessageRoot"
],
[
"FieldError",
"FieldErrorRoot"
],
[
"Fieldset",
"FieldsetRoot"
],
[
"Form",
"FormRoot"
],
[
"Header",
"HeaderRoot"
],
[
"Input",
"InputRoot"
],
[
"InputGroup",
"InputGroupRoot"
],
[
"InputOTP",
"InputOTPRoot"
],
[
"Kbd",
"KbdRoot"
],
[
"Label",
"LabelRoot"
],
[
"Link",
"LinkRoot"
],
[
"ListBox",
"ListBoxRoot"
],
[
"ListBoxItem",
"ListBoxItemRoot"
],
[
"ListBoxSection",
"ListBoxSectionRoot"
],
[
"Menu",
"MenuRoot"
],
[
"MenuItem",
"MenuItemRoot"
],
[
"MenuSection",
"MenuSectionRoot"
],
[
"Meter",
"MeterRoot"
],
[
"Modal",
"ModalRoot"
],
[
"NumberField",
"NumberFieldRoot"
],
[
"Pagination",
"PaginationRoot"
],
[
"Popover",
"PopoverRoot"
],
[
"ProgressBar",
"ProgressBarRoot"
],
[
"ProgressCircle",
"ProgressCircleRoot"
],
[
"Radio",
"RadioRoot"
],
[
"RadioGroup",
"RadioGroupRoot"
],
[
"RangeCalendar",
"RangeCalendarRoot"
],
[
"ScrollShadow",
"ScrollShadowRoot"
],
[
"SearchField",
"SearchFieldRoot"
],
[
"Select",
"SelectRoot"
],
[
"Separator",
"SeparatorRoot"
],
[
"Skeleton",
"SkeletonRoot"
],
[
"Slider",
"SliderRoot"
],
[
"Spinner",
"SpinnerRoot"
],
[
"Surface",
"SurfaceRoot"
],
[
"Switch",
"SwitchRoot"
],
[
"SwitchGroup",
"SwitchGroupRoot"
],
[
"Table",
"TableRoot"
],
[
"Tabs",
"TabsRoot"
],
[
"Tag",
"TagRoot"
],
[
"TagGroup",
"TagGroupRoot"
],
[
"TextArea",
"TextAreaRoot"
],
[
"TextField",
"TextFieldRoot"
],
[
"TimeField",
"TimeFieldRoot"
],
[
"ToggleButton",
"ToggleButtonRoot"
],
[
"ToggleButtonGroup",
"ToggleButtonGroupRoot"
],
[
"Toolbar",
"ToolbarRoot"
],
[
"Tooltip",
"TooltipRoot"
],
[
"Typography",
"TypographyRoot"
]
],
"css": []
},
@@ -446,3 +446,94 @@ it("ComboBox trigger retains a caller disabled attribute", async () => {
)!.disabled,
).toBe(true);
});
it("Autocomplete value slot carries the source items for trigger composition", async () => {
const source = [{ id: 1, textValue: "Kate", avatarUrl: "/kate.png" }];
let state: {
isPlaceholder: boolean;
selectedItem: { key: unknown; item?: { avatarUrl?: string } } | null;
selectedItems: { key: unknown; item?: { avatarUrl?: string } }[];
} | null = null;
const w = mount(
defineComponent({
render: () =>
h(
Autocomplete,
{
items: source as never,
defaultValue: 1,
"aria-label": "Picker",
selectionMode: "single",
},
{
default: () => [
h(AutocompleteTrigger, null, {
default: () =>
h(AutocompleteValue, null, {
default: (slotState: typeof state) => {
state = slotState as never;
return "";
},
}),
}),
h(AutocompletePopover, null, {
default: () =>
h(ListBox, null, {
default: () =>
source.map((item) =>
h(
ListBoxItem,
{ id: item.id, textValue: item.textValue },
() => item.textValue,
),
),
}),
}),
],
},
),
}),
{ attachTo: document.body },
);
roots.push(w);
await tick();
expect(state).not.toBeNull();
expect(state!.isPlaceholder).toBe(false);
// The source entry rides along: no consumer-side key lookups needed.
expect(state!.selectedItem?.key).toBe(1);
expect(state!.selectedItem?.item?.avatarUrl).toBe("/kate.png");
expect(state!.selectedItems[0].item?.avatarUrl).toBe("/kate.png");
});
it("ComboBox root slot exposes the selected source item", async () => {
const source = [
{ id: "a", textValue: "Alpha", meta: "first" },
{ id: "b", textValue: "Beta", meta: "second" },
];
let state: { selectedItem: { id?: unknown; meta?: unknown } | null } | null =
null;
const w = mount(
defineComponent({
render: () =>
h(
ComboBox,
{ items: source as never, defaultValue: "b", "aria-label": "Picker" },
{
default: (slotState: typeof state) => {
state = slotState as never;
return [
h(ComboBoxInputGroup, null, {
default: () => [h(Input), h(ComboBoxTrigger)],
}),
];
},
},
),
}),
{ attachTo: document.body },
);
roots.push(w);
await tick();
expect(state!.selectedItem?.id).toBe("b");
expect(state!.selectedItem?.meta).toBe("second");
});