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();
});