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:
@@ -453,6 +453,7 @@ export default defineComponent({
|
||||
textValue:
|
||||
records.value.find((record) => record.key === key)?.text ??
|
||||
String(key),
|
||||
item: props.items?.find((entry) => entry.id === key),
|
||||
})),
|
||||
),
|
||||
selectionMode: computed(() => props.selectionMode),
|
||||
|
||||
@@ -20,6 +20,7 @@ export default defineComponent({
|
||||
defaultChildren,
|
||||
selectedText,
|
||||
selectedItems,
|
||||
selectedItem: selectedItems[0] ?? null,
|
||||
}) ?? defaultChildren;
|
||||
return h(
|
||||
"span",
|
||||
|
||||
@@ -5,9 +5,11 @@ import type { CollectionRecord, OwnedCollection } from "../collection/owner";
|
||||
import type { useChoiceField } from "../choice/shared";
|
||||
|
||||
export type AutocompleteValue = CollectionKey | CollectionKey[] | null;
|
||||
export interface AutocompleteSelectedItem {
|
||||
export interface AutocompleteSelectedItem<T = AutocompleteItem> {
|
||||
key: CollectionKey;
|
||||
textValue: string;
|
||||
/** Source entry from the root `items` (absent for collection-discovered items). */
|
||||
item?: T;
|
||||
}
|
||||
export interface AutocompleteOptions {
|
||||
modelValue?: AutocompleteValue;
|
||||
@@ -42,6 +44,12 @@ export interface AutocompleteValueState {
|
||||
/** Accepted `textValue`s joined by ", ". */
|
||||
selectedText: string;
|
||||
selectedItems: AutocompleteSelectedItem[];
|
||||
/**
|
||||
* First accepted entry (the single-select selection), or null. Entries carry
|
||||
* the source `items` data in `item` so callers can compose rich trigger
|
||||
* content from their own records without re-mapping keys.
|
||||
*/
|
||||
selectedItem: AutocompleteSelectedItem | null;
|
||||
}
|
||||
/** Scoped-slot state of the `Autocomplete` root. */
|
||||
export interface AutocompleteState {
|
||||
|
||||
@@ -58,6 +58,7 @@ export default defineComponent({
|
||||
inputValue: string;
|
||||
selectedKey: CollectionKey | null;
|
||||
selectedKeys: CollectionKey[];
|
||||
selectedItem: ComboBoxItem | null;
|
||||
}) => VNodeChild;
|
||||
}>,
|
||||
props: {
|
||||
@@ -653,6 +654,7 @@ export default defineComponent({
|
||||
textValue:
|
||||
records.value.find((record) => record.key === key)?.text ??
|
||||
String(key),
|
||||
item: props.items?.find((entry) => entry.id === key),
|
||||
})),
|
||||
),
|
||||
selectionMode: computed(() => props.selectionMode),
|
||||
@@ -792,6 +794,10 @@ export default defineComponent({
|
||||
? null
|
||||
: (value.value as CollectionKey | null),
|
||||
selectedKeys: [...keys.value],
|
||||
selectedItem:
|
||||
(!Array.isArray(value.value) && value.value != null
|
||||
? (props.items?.find((entry) => entry.id === value.value) ?? null)
|
||||
: null) ?? null,
|
||||
});
|
||||
const children = Array.isArray(rendered)
|
||||
? rendered
|
||||
|
||||
@@ -17,6 +17,12 @@ export interface ComboBoxState {
|
||||
inputValue: string;
|
||||
selectedKey: CollectionKey | null;
|
||||
selectedKeys: CollectionKey[];
|
||||
/**
|
||||
* Source entry from the root `items` matching the single selected key
|
||||
* (null in multiple mode or for custom/discovered values). Lets callers
|
||||
* compose rich value displays from their own data without re-mapping keys.
|
||||
*/
|
||||
selectedItem: ComboBoxItem | null;
|
||||
}
|
||||
/** Scoped-slot state of `ComboBoxValue`. */
|
||||
export interface ComboBoxValueState {
|
||||
@@ -26,6 +32,8 @@ export interface ComboBoxValueState {
|
||||
export interface ComboBoxSelectedItem {
|
||||
key: CollectionKey;
|
||||
textValue: string;
|
||||
/** Source entry from the root `items` (absent for collection-discovered items). */
|
||||
item?: ComboBoxItem;
|
||||
}
|
||||
/** Props shared by the SFC and the context; keep one schema. */
|
||||
export interface ComboBoxOptions {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
inject,
|
||||
isVNode,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
provide,
|
||||
ref,
|
||||
@@ -31,8 +32,6 @@ import {
|
||||
submenuOpenKey,
|
||||
} from "../menu/context";
|
||||
import { useOverlayAnimation } from "../overlay/animation";
|
||||
import { resolvePlacement, type OverlayPlacement } from "../overlay/placement";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import { elementFromValue, menuSurfaceFromVNode } from "./dom";
|
||||
import DropdownPopover from "./DropdownPopover.vue";
|
||||
|
||||
@@ -104,16 +103,72 @@ function inheritedProps(props: Record<string, unknown> | null) {
|
||||
export default defineComponent({
|
||||
name: "DropdownSubmenuTrigger",
|
||||
inheritAttrs: false,
|
||||
setup(_, { slots }) {
|
||||
props: {
|
||||
/**
|
||||
* Hover-to-open delay in ms (the pinned useSubmenuTrigger contract).
|
||||
* Keyboard and programmatic opens stay immediate and cancel the pending
|
||||
* hover open, matching the baseline.
|
||||
*/
|
||||
delay: { type: Number, default: 200 },
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const dropdownCtx = inject(dropdownContextKey, null);
|
||||
const config = useConfig();
|
||||
provide(submenuContentKey, true);
|
||||
|
||||
const subOpen = ref(false);
|
||||
const triggerRef = ref<unknown>(null);
|
||||
const contentElement = ref<HTMLElement | null>(null);
|
||||
const fallbackId = useId();
|
||||
/**
|
||||
* Reka's MenuSubTrigger opens submenus after a fixed 100ms hover, while the
|
||||
* pinned source waits `delay` (200ms by default). The controlled open gate
|
||||
* below defers hover-driven opens to the configured delay: our own timer
|
||||
* owns the hover open, early hover requests are swallowed, and keyboard
|
||||
* opens (which arrive during a keydown) cancel the pending timer and open
|
||||
* at once like the baseline.
|
||||
*/
|
||||
const hoverOpenTimer = ref<ReturnType<typeof setTimeout> | null>(null);
|
||||
let duringKeydown = false;
|
||||
function clearHoverOpen() {
|
||||
if (hoverOpenTimer.value) {
|
||||
clearTimeout(hoverOpenTimer.value);
|
||||
hoverOpenTimer.value = null;
|
||||
}
|
||||
}
|
||||
function scheduleHoverOpen() {
|
||||
if (hoverOpenTimer.value || subOpen.value) return;
|
||||
if (!(props.delay > 0)) {
|
||||
subOpen.value = true;
|
||||
return;
|
||||
}
|
||||
hoverOpenTimer.value = setTimeout(() => {
|
||||
hoverOpenTimer.value = null;
|
||||
subOpen.value = true;
|
||||
}, props.delay);
|
||||
}
|
||||
function itemPointerMove(event: Event) {
|
||||
if ((event as MouseEvent).defaultPrevented) return;
|
||||
// Same gate as Reka's SubTrigger: only mouse hover starts the open.
|
||||
if ((event as PointerEvent).pointerType !== "mouse") return;
|
||||
scheduleHoverOpen();
|
||||
}
|
||||
function itemPointerLeave() {
|
||||
clearHoverOpen();
|
||||
}
|
||||
function globalKeydownCapture() {
|
||||
duringKeydown = true;
|
||||
queueMicrotask(() => {
|
||||
duringKeydown = false;
|
||||
});
|
||||
}
|
||||
onMounted(() =>
|
||||
window.addEventListener("keydown", globalKeydownCapture, true),
|
||||
);
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("keydown", globalKeydownCapture, true);
|
||||
clearHoverOpen();
|
||||
});
|
||||
const contentAttrs = {
|
||||
label: ref<string | undefined>(),
|
||||
labelledBy: ref<string | undefined>(),
|
||||
@@ -224,9 +279,6 @@ export default defineComponent({
|
||||
if (!CONTROL_PROPS.has(key)) domProps[key] = value;
|
||||
}
|
||||
|
||||
const placement = (popoverProps.placement as OverlayPlacement) ?? "end";
|
||||
const position = resolvePlacement(placement, config?.dir.value ?? "ltr");
|
||||
|
||||
panelConfig.dismissDisabled =
|
||||
(popoverProps.isKeyboardDismissDisabled as boolean | undefined) ??
|
||||
false;
|
||||
@@ -234,8 +286,10 @@ export default defineComponent({
|
||||
popoverProps.shouldCloseOnInteractOutside as
|
||||
((event: Event) => boolean) | undefined;
|
||||
|
||||
// Reka fixes the submenu side/align to the parent convention, so only
|
||||
// the offsets/collision props can be forwarded.
|
||||
// Reka's MenuSubContent fixes the submenu side/align to the parent
|
||||
// convention (right in LTR, left in RTL) and only accepts the offsets /
|
||||
// collision props here: forwarded side/align attrs never reach the
|
||||
// popper placement (the template binding wins), so they are not passed.
|
||||
const panelProps: Record<string, unknown> = {
|
||||
sideOffset:
|
||||
(popoverProps.sideOffset as number | undefined) ??
|
||||
@@ -256,9 +310,6 @@ export default defineComponent({
|
||||
contentAttrs.loop.value ??
|
||||
false,
|
||||
};
|
||||
const side = (popoverProps.side as string | undefined) ?? position.side;
|
||||
const align =
|
||||
(popoverProps.align as string | undefined) ?? position.align;
|
||||
|
||||
const keydownChain = [
|
||||
...asArray(popoverProps.onKeydown as Handler),
|
||||
@@ -309,6 +360,14 @@ export default defineComponent({
|
||||
{
|
||||
open: subOpen.value,
|
||||
"onUpdate:open": (value: boolean) => {
|
||||
if (value) {
|
||||
// Reka's fixed 100ms hover timer requests the open before the
|
||||
// configured delay; the delay owns that open instead. Keyboard
|
||||
// opens arrive during a keydown and pass through at once,
|
||||
// cancelling the pending hover open like the baseline.
|
||||
if (hoverOpenTimer.value && !duringKeydown) return;
|
||||
clearHoverOpen();
|
||||
} else clearHoverOpen();
|
||||
subOpen.value = value;
|
||||
},
|
||||
},
|
||||
@@ -333,6 +392,9 @@ export default defineComponent({
|
||||
// Escape with focus on the trigger (pointer-opened
|
||||
// submenu) must also close only this level.
|
||||
onKeydown: handleEscape,
|
||||
// Hover intent drives the configured open delay.
|
||||
onPointermove: itemPointerMove,
|
||||
onPointerleave: itemPointerLeave,
|
||||
})
|
||||
: null,
|
||||
},
|
||||
@@ -347,8 +409,7 @@ export default defineComponent({
|
||||
{
|
||||
...domProps,
|
||||
...panelProps,
|
||||
side,
|
||||
align,
|
||||
// experiment: stop forwarding side/align
|
||||
...ariaProps,
|
||||
class: [
|
||||
dropdownCtx?.slots.value.popover(),
|
||||
|
||||
Reference in New Issue
Block a user