feat(collection): add optional filtering and virtual focus for composite pickers
ComboBox and Autocomplete need two capabilities the collection protocol did not express: filtering a collection by an external input value, and keeping DOM focus in the composite's input while an active option is tracked for aria-activedescendant. Both are opt-in members on CollectionOwner plus optionId/reveal on the owned collection. Standalone ListBox and Select provide none of them and keep their previous behaviour: DOM focus still moves into the list, one roving tab stop, no row filtering. Filtered rows stay mounted with data-filtered (display:none) so their text and accepted selection survive; only display, aria positions and keyboard navigation see the visible subset. Under virtual focus the list never takes DOM focus, never exposes a roving tab stop, and leaves keyboard handling to the composite; reveal() scrolls a virtualized window and waits for the row to mount before the composite reads its id. Includes the playground verification page, a ten-case suite and the B02a section of the migration report.
This commit is contained in:
@@ -1,16 +1,35 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
import type { ComputedRef, InjectionKey, Ref } from "vue";
|
||||
import type { CollectionKey } from "./keys";
|
||||
export interface CollectionRecord {
|
||||
key: CollectionKey;
|
||||
text: string;
|
||||
disabled: boolean;
|
||||
}
|
||||
/** Filtering and virtual focus are optional: absent means the previous behaviour. */
|
||||
export interface CollectionView {
|
||||
/**
|
||||
* Filter over the full data set. Filtered-out records stay mounted and keep
|
||||
* their text/selection, but leave display and keyboard navigation.
|
||||
*/
|
||||
filter?: (record: CollectionRecord) => boolean;
|
||||
/** Keep DOM focus outside the collection and track `activeKey` instead. */
|
||||
virtualFocus?: () => boolean;
|
||||
/** Active key for virtual focus; the owning composite drives it. */
|
||||
activeKey?: Ref<CollectionKey | undefined>;
|
||||
}
|
||||
export interface OwnedCollection {
|
||||
items: () => CollectionRecord[];
|
||||
focus: (edge: "first" | "last" | "selected") => Promise<void>;
|
||||
/** Mounted DOM id of an option, for `aria-activedescendant`. */
|
||||
optionId?: (key: CollectionKey) => string | undefined;
|
||||
/**
|
||||
* Make `key` the revealed row: scroll a virtualized window first, then wait
|
||||
* for the row to mount. Never moves DOM focus.
|
||||
*/
|
||||
reveal?: (key: CollectionKey) => Promise<void>;
|
||||
}
|
||||
/** A field composite may own a ListBox, without adding another value store. */
|
||||
export interface CollectionOwner {
|
||||
export interface CollectionOwner extends CollectionView {
|
||||
keys: ComputedRef<readonly CollectionKey[]>;
|
||||
mode: ComputedRef<"single" | "multiple">;
|
||||
disabled: ComputedRef<boolean>;
|
||||
|
||||
Reference in New Issue
Block a user