feat(autocomplete): migrate Autocomplete with popover-owned filtering
Port the fixed-baseline Autocomplete onto the B02a collection protocol. The trigger is the single Tab entry; opening moves focus to the search box inside the popover, which owns filtering, aria-activedescendant and keyboard navigation while the list only tracks an active row. - Seven parts: root (field, value/open models, form value, owner wiring), trigger (anchor + activation), value (scoped slot with selectedItems and selectedText instead of copied item subtrees), indicator, clear button, popover (measured trigger width), filter (owns the search text and composes the inner SearchFieldInput into the combobox control). - Filter exposes input-value/update:inputValue/inputChange, matching ComboBox. - Confirming the active row in multiple mode now toggles it instead of replacing the accepted set (ComboBox shared the same bug). - ComboBox shows the accepted label on the first render via a display value that falls back to the selected record, so preselected fields are readable before the selection watcher runs (including SSR). - Popovers measure the anchor with a ResizeObserver because Reka does not publish the anchor size; the caller's root class is merged again so the trigger fills the field width. - 24 baseline previews, Chinese doc page, navigation, 17 behaviour tests, 5 demo/document contracts and an independent tarball consumption script for both pickers. Not included: the full bundler/NodeNext type matrix (B02d).
This commit is contained in:
@@ -32,7 +32,7 @@ import {
|
||||
type CollectionRecord,
|
||||
type OwnedCollection,
|
||||
} from "../collection/owner";
|
||||
import { planComboBoxItems } from "./metadata";
|
||||
import { planCollectionItems } from "./metadata";
|
||||
import {
|
||||
comboBoxKey,
|
||||
type ComboBoxItem,
|
||||
@@ -271,6 +271,7 @@ export default defineComponent({
|
||||
const activeKey = ref<CollectionKey>();
|
||||
const cursor = ref<CollectionKey>();
|
||||
const inputElement = ref<HTMLInputElement>();
|
||||
const triggerElement = ref<HTMLElement>();
|
||||
let anchor: (() => HTMLElement | undefined) | undefined;
|
||||
const registerAnchor = (element: () => HTMLElement | undefined) => {
|
||||
anchor = element;
|
||||
@@ -377,6 +378,14 @@ export default defineComponent({
|
||||
(item) => item.key === key && filter(item) && !item.disabled,
|
||||
);
|
||||
if (!record) return;
|
||||
if (props.selectionMode === "multiple") {
|
||||
// Confirming the active row toggles it inside the accepted set.
|
||||
const next = keys.value.includes(key)
|
||||
? keys.value.filter((item) => item !== key)
|
||||
: [...keys.value, key];
|
||||
request(next);
|
||||
return;
|
||||
}
|
||||
request([key]);
|
||||
}
|
||||
|
||||
@@ -397,6 +406,20 @@ export default defineComponent({
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/**
|
||||
* The visible text falls back to the accepted item's label so an initial or
|
||||
* external selection is readable on the very first render (including SSR),
|
||||
* before the selection-sync watcher has run.
|
||||
*/
|
||||
const displayInputValue = computed(() => {
|
||||
if (inputValue.value) return inputValue.value;
|
||||
if (props.selectionMode !== "single") return "";
|
||||
const selected = records.value.find((record) =>
|
||||
keys.value.includes(record.key),
|
||||
);
|
||||
return selected?.text ?? "";
|
||||
});
|
||||
|
||||
function setInputValue(next: string) {
|
||||
inputModel.request(next);
|
||||
if (props.menuTrigger === "input" && !open.value && next) setOpen(true);
|
||||
@@ -557,6 +580,7 @@ export default defineComponent({
|
||||
open,
|
||||
setOpen,
|
||||
inputValue,
|
||||
displayInputValue,
|
||||
setInputValue,
|
||||
inputId,
|
||||
listId,
|
||||
@@ -580,6 +604,7 @@ export default defineComponent({
|
||||
menuTrigger: () => props.menuTrigger,
|
||||
inputElement,
|
||||
registerAnchor,
|
||||
triggerElement,
|
||||
inputProps,
|
||||
formValueText,
|
||||
invalid,
|
||||
@@ -638,7 +663,7 @@ export default defineComponent({
|
||||
: rendered == null
|
||||
? []
|
||||
: [rendered];
|
||||
const plan = planComboBoxItems(children);
|
||||
const plan = planCollectionItems(children);
|
||||
if (JSON.stringify(plan.records) !== JSON.stringify(planned.value))
|
||||
planned.value = plan.records;
|
||||
complete.value = plan.complete;
|
||||
|
||||
Reference in New Issue
Block a user