fix(collection): close the six review gaps in filtering and virtual focus
- Keep the composite input focused on real pointer presses: cancel the default focus transfer for plain row presses only, leaving nested controls and already cancelled callers alone. - Drive the virtual window, total height, reveal index and aria positions from the visible subset, and render the empty channel when filtering removes every row. Non-virtualized rows stay mounted and are hidden, so their text and accepted selection survive. - Scroll mounted rows for reveal/focus outside virtualization, wait for a virtualized row to mount (frame-based, bounded), and drop reveal requests that filtering, closing or unmounting made obsolete. - Stop overwriting caller `hidden`: mergeProps deletes an earlier key when a later value is undefined, so the filter now only adds `hidden` when the caller did not set it. - Share keyboard modality through an optional `keyboardIntent` ref so a pointer press no longer leaves the active row without data-focus-visible. - Give the verification harness instance-unique ids and derive aria-activedescendant from open state, mounted id and filter visibility. Adds the reviewer probe plus eight regressions, and a virtualized harness instance for the browser smoke of filtering plus window/height/positions.
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { computed, defineComponent, h, nextTick, provide, ref } from "vue";
|
||||
import { ListBox, ListBoxItem } from "../packages/vue/src";
|
||||
import {
|
||||
collectionOwnerKey,
|
||||
type CollectionOwner,
|
||||
type OwnedCollection,
|
||||
} from "../packages/vue/src/components/collection/owner";
|
||||
import Harness from "../packages/vue/tests/fixtures/FilterVirtualCombobox.vue";
|
||||
const mounted: { unmount(): void }[] = [];
|
||||
afterEach(() => {
|
||||
while (mounted.length) mounted.pop()!.unmount();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
const settle = async () => {
|
||||
await nextTick();
|
||||
await new Promise((r) => setTimeout(r, 3));
|
||||
};
|
||||
function setupList(virtualized = false) {
|
||||
let collection: OwnedCollection | undefined;
|
||||
const items = Array.from({ length: 6 }, (_, id) => ({
|
||||
id,
|
||||
textValue: `Row ${id}`,
|
||||
}));
|
||||
const activeKey = ref<string | number>();
|
||||
const owner: CollectionOwner = {
|
||||
keys: computed(() => []),
|
||||
mode: computed(() => "single"),
|
||||
disabled: computed(() => false),
|
||||
readOnly: computed(() => false),
|
||||
disabledKeys: computed(() => []),
|
||||
id: "probe",
|
||||
labelledBy: () => undefined,
|
||||
ariaLabel: () => "Probe",
|
||||
request: () => {},
|
||||
action: () => {},
|
||||
leave: () => {},
|
||||
connect: (c) => {
|
||||
collection = c;
|
||||
return () => {
|
||||
collection = undefined;
|
||||
};
|
||||
},
|
||||
filter: (r) => r.key === 3,
|
||||
virtualFocus: () => true,
|
||||
activeKey,
|
||||
};
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
setup() {
|
||||
provide(collectionOwnerKey, owner);
|
||||
return () =>
|
||||
h(
|
||||
ListBox,
|
||||
{ items, virtualized, rowHeight: 40, overscan: 8 },
|
||||
{
|
||||
default: ({ item }: { item: (typeof items)[number] }) =>
|
||||
h(ListBoxItem, { id: item.id }, () => item.textValue),
|
||||
},
|
||||
);
|
||||
},
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
mounted.push(wrapper);
|
||||
return { wrapper, collection: () => collection };
|
||||
}
|
||||
it("preserves caller hidden on an ordinary ListBoxItem", async () => {
|
||||
const w = mount(ListBox, {
|
||||
slots: {
|
||||
default: () =>
|
||||
h(ListBoxItem, { id: "hidden", hidden: true }, () => "Hidden"),
|
||||
},
|
||||
});
|
||||
mounted.push(w);
|
||||
await settle();
|
||||
expect(w.find('[role="option"]').attributes("hidden")).toBeDefined();
|
||||
});
|
||||
it("reveal scrolls a mounted ordinary row without moving DOM focus", async () => {
|
||||
const { wrapper, collection } = setupList();
|
||||
await settle();
|
||||
const node = wrapper.findAll('[role="option"]')[3].element;
|
||||
const scroll = vi.fn();
|
||||
Object.defineProperty(node, "scrollIntoView", {
|
||||
configurable: true,
|
||||
value: scroll,
|
||||
});
|
||||
await collection()!.reveal!(3);
|
||||
expect(scroll).toHaveBeenCalled();
|
||||
});
|
||||
it("virtual window contains no fixed height slots for filtered-out rows", async () => {
|
||||
const { wrapper } = setupList(true);
|
||||
await settle();
|
||||
expect(
|
||||
wrapper.findAll(
|
||||
'[data-slot="list-box-virtual-content"] > [role="presentation"]',
|
||||
),
|
||||
).toHaveLength(1);
|
||||
});
|
||||
it("restores keyboard highlight intent after a pointer interaction", async () => {
|
||||
const w = mount(Harness, { attachTo: document.body });
|
||||
mounted.push(w);
|
||||
await settle();
|
||||
const input = w.find("input");
|
||||
await input.setValue("");
|
||||
await settle();
|
||||
await w.findAll('[role="option"]')[0].trigger("pointerdown");
|
||||
await input.trigger("keydown", { key: "ArrowDown" });
|
||||
await settle();
|
||||
expect(w.find('[data-focused="true"]').attributes("data-focus-visible")).toBe(
|
||||
"true",
|
||||
);
|
||||
});
|
||||
it("has instance-unique names and controls in the verification harness", async () => {
|
||||
const w = mount(
|
||||
defineComponent({ setup: () => () => h("div", [h(Harness), h(Harness)]) }),
|
||||
);
|
||||
mounted.push(w);
|
||||
await settle();
|
||||
const ids = w.findAll("[id]").map((n) => n.attributes("id"));
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
});
|
||||
Reference in New Issue
Block a user