From ff486fb665a7934adddfe43cc64c500ba4755f55 Mon Sep 17 00:00:00 2001 From: maoyingjie Date: Sun, 25 Oct 2026 16:45:07 +0800 Subject: [PATCH] fix(collection): finish B02a boundary checks and stage acceptance --- docs/migrations/B02-combobox-autocomplete.md | 4 ++ docs/migrations/B02a-acceptance.md | 31 +++++++++++++ docs/verification.md | 4 ++ .../vue/src/components/list-box/ListBox.vue | 2 +- .../src/components/list-box/ListBoxItem.vue | 7 ++- tests/collection-filter-virtual.test.ts | 44 +++++++++++++++++++ tests/setup/scroll.ts | 9 ++++ vitest.config.ts | 2 +- 8 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 docs/migrations/B02a-acceptance.md create mode 100644 tests/setup/scroll.ts diff --git a/docs/migrations/B02-combobox-autocomplete.md b/docs/migrations/B02-combobox-autocomplete.md index 19f84c1..3ac4fd1 100644 --- a/docs/migrations/B02-combobox-autocomplete.md +++ b/docs/migrations/B02-combobox-autocomplete.md @@ -245,3 +245,7 @@ export interface CollectionOwner extends CollectionView { - 真实系统 IME 与读屏软件(自动化后端无法产生系统组合输入;本轮不新增门槛)。 - 指针按下态的浏览器原生序列(自动化只能给出 click,`pointerdown` 单独按下态由 jsdom 覆盖);嵌套控件点击隔离同样以 jsdom 覆盖(浏览器侧需注入 DOM,未做)。 + +## 11. B02a 阶段复核通过 + +以 [B02a 阶段验收](B02a-acceptance.md) 为当前结论。集成人补齐静态空集合、嵌套控件按下状态及探针独立运行的 scrollTo 环境初始化;最新全套为 77 文件 / 1026 项,无未处理错误。仅放行 B02a,在当前任务分支连续完成 B02b、B02c、B02d,公共组件和完整示例尚未验收。 diff --git a/docs/migrations/B02a-acceptance.md b/docs/migrations/B02a-acceptance.md new file mode 100644 index 0000000..5061190 --- /dev/null +++ b/docs/migrations/B02a-acceptance.md @@ -0,0 +1,31 @@ +# B02a 共享协议阶段验收(2026-10-25) + +复核起点 `c8b0aa2`,仍在 `feat/b02-combobox-autocomplete`。本记录只放行 B02a,不代表公共 ComboBox/Autocomplete、48 个预览或完整 B02 已完成;未合 main、未推送。 + +## 协议结论 + +- 接受可选 owner 过滤、输入端虚拟焦点、共享键盘意图与 isOpen 失效边界;optionId/reveal 由集合实现。 +- 完整元数据供选择/标签,虚拟窗口与滚动索引使用过滤后的可见数据。未挂载记录的 textValue/isDisabled 由组合体提供,不能依赖 DOM 补全集。 +- 虚拟测量、scrollTo、onScroll 使用同一实际滚动容器。普通静态成员可保留隐藏 DOM;虚拟成员按窗口挂载。 +- 输入组合体负责键盘/IME、确认与关闭;集合清理无效活动 key。已接受值与当前可确认活动项独立。 + +## 集成人收尾 + +1. 静态集合初始为空或移除最后一项时,原 visibleIsEmpty 依赖 known().length>0,永远无法显示 empty。改为以已挂载生命周期判断集合稳定,保留默认插槽成员与可见集合判空。 +2. 嵌套按钮的 click 已隔离,但 pointerdown 仍设置父选项 pressed。按下状态也排除嵌套交互目标,不拦截控件自身默认行为。 +3. 第二轮探针独立运行发生未处理拒绝:jsdom 无 Element.scrollTo。增加独立 setup 文件并在每个测试环境初始化;不依赖另一测试文件先执行。不模拟布局,不把 shim 当作滚动几何证据。 + +两项新增行为回归先在修复前失败,修复后通过。 + +## 验证结果 + +- 相关 5 文件 **98 项通过**,无未处理错误;第二轮 7 项探针单独运行通过。 +- 全套 **77 文件 / 1026 项通过**,无未处理错误;typecheck、文档生产构建、Prettier、git diff --check 通过。文档保留既有 chunk 体积提示。 +- 浏览器 localhost:5182:真实虚拟列表 clientHeight=144、scrollHeight=1448;导航到第39行时 scrollTop=1304、仅挂载8行,活动行位于列表受限视口内,输入框保持焦点。上一轮“40行全部挂载”的假窗口已修复。 +- 原有 ListBox/Select 回归包含在上述测试中;不重新宣称源样式已经逐像素验收。 + +未验证物理系统 IME、读屏软件及完整公共组件的独立产物消费;后者在 B02d 统一完成。B02a 未要求新增服务端专项。 + +## 接续 + +允许在当前分支继续 B02b ComboBox → B02c Autocomplete → B02d 收口,各段独立提交。先确认包含本次收尾提交,不从尚未包含 B02a 的 main/origin/main 重新开工;这些是同一批的阶段,不是新的独立批次。保留原始源契约/全部48个预览清单,B02d 集中交回复核,期间不合 main、不推送。 diff --git a/docs/verification.md b/docs/verification.md index 4de4801..33778f9 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -1013,3 +1013,7 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除 ## B03 复核与接手修复(2026-10-25) Tag/TagGroup/ErrorMessage 的最新验收见 [B03 复核记录](migrations/B03-review-acceptance.md)。修复属性透传、子控件键盘所有权、禁用/按下状态、gridcell、单 Tab 入口、asChild 和真实浏览器移除焦点时序;新增确认移除公告。47 项本批测试、全套 985 项、类型/文档构建与独立 tarball 消费通过。浏览器仅重点检查移除与键盘,不宣称全量视觉或读屏验收。 + +## B02a 共享协议阶段(2026-10-25) + +阶段复核见 [B02a 验收](migrations/B02a-acceptance.md)。过滤/虚拟焦点协议及真实受限虚拟窗口通过重点验证;静态空集合、嵌套按下状态和测试环境由集成人补齐。相关98项、全套1026项、类型/文档构建通过,无未处理错误。只允许继续B02b–d,不代表ComboBox/Autocomplete公共迁移完成。 diff --git a/packages/vue/src/components/list-box/ListBox.vue b/packages/vue/src/components/list-box/ListBox.vue index f81b6d4..cb38117 100644 --- a/packages/vue/src/components/list-box/ListBox.vue +++ b/packages/vue/src/components/list-box/ListBox.vue @@ -163,7 +163,7 @@ const visibleKeys = computed( const eligible = () => visibleKnown().filter((item) => !item.disabled); /** Empty channel needs a settled collection: static children register on mount. */ const visibleIsEmpty = computed( - () => visibleKeys.value.size === 0 && (!!props.items || known().length > 0), + () => visibleKeys.value.size === 0 && (!!props.items || mounted.value), ); // A removed, disabled or filtered-out row cannot stay active. The collection diff --git a/packages/vue/src/components/list-box/ListBoxItem.vue b/packages/vue/src/components/list-box/ListBoxItem.vue index 629d23c..68e277b 100644 --- a/packages/vue/src/components/list-box/ListBoxItem.vue +++ b/packages/vue/src/components/list-box/ListBoxItem.vue @@ -249,7 +249,12 @@ export default defineComponent({ // calls preventDefault, otherwise every row would look cancelled. const cancelled = event.defaultPrevented; keepInputFocus(event); - if (!cancelled && !disabled.value && event.button === 0) + if ( + !cancelled && + !disabled.value && + event.button === 0 && + !nestedInteractive(event.target) + ) pressed.value = true; }, onMousedown: (event: MouseEvent) => { diff --git a/tests/collection-filter-virtual.test.ts b/tests/collection-filter-virtual.test.ts index bfe5630..4a99998 100644 --- a/tests/collection-filter-virtual.test.ts +++ b/tests/collection-filter-virtual.test.ts @@ -708,3 +708,47 @@ describe("B02a round 2 regressions", () => { expect(wrapper.vm.eligible().map((record) => record.key)).toEqual([99]); }); }); + +describe("B02a final boundary checks", () => { + it("shows static empty feedback for an initially empty or removed collection", async () => { + const options = ref([]); + const wrapper = mount( + defineComponent({ + setup: () => () => + h(ListBox, null, { + default: () => + options.value.map((id) => + h(ListBoxItem, { id, key: id }, () => id), + ), + empty: () => h("p", { "data-test": "static-empty" }, "Empty"), + }), + }), + { attachTo: document.body }, + ); + wrappers.push(wrapper); + await nextTick(); + await settle(); + expect(queryOne('[data-test="static-empty"]')).not.toBeNull(); + options.value = ["A"]; + await nextTick(); + await settle(); + expect(queryOne('[data-test="static-empty"]')).toBeNull(); + options.value = []; + await nextTick(); + await settle(); + expect(queryOne('[data-test="static-empty"]')).not.toBeNull(); + }); + + it("does not press the parent row from an embedded control", async () => { + await mountHarness(); + await type(""); + const row = queryAll('[role="option"]')[0]; + const button = document.createElement("button"); + row.appendChild(button); + const down = pointerEvent("pointerdown"); + button.dispatchEvent(down); + await nextTick(); + expect(down.defaultPrevented).toBe(false); + expect(row.hasAttribute("data-pressed")).toBe(false); + }); +}); diff --git a/tests/setup/scroll.ts b/tests/setup/scroll.ts new file mode 100644 index 0000000..4751fb4 --- /dev/null +++ b/tests/setup/scroll.ts @@ -0,0 +1,9 @@ +/** jsdom has no Element.scrollTo. Supply only the method used by VueUse; + * geometry and visible-window assertions still belong to real browser checks. + * Set up each test realm explicitly so probes work alone and in any order. */ +if ( + typeof Element !== "undefined" && + typeof Element.prototype.scrollTo !== "function" +) { + Element.prototype.scrollTo = () => {}; +} diff --git a/vitest.config.ts b/vitest.config.ts index a93840a..ffb5ea5 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -26,6 +26,6 @@ export default defineConfig({ test: { environment: "jsdom", include: ["tests/**/*.test.ts"], - setupFiles: ["tests/setup/cssom.ts"], + setupFiles: ["tests/setup/cssom.ts", "tests/setup/scroll.ts"], }, });