feat(combo-box): migrate ComboBox with input-owned focus and filtering

Port the fixed-baseline ComboBox onto the B02a collection protocol: the input
keeps real DOM focus, the list only tracks an active row, and filtering reuses
the owner filter instead of a second collection kernel.

- Five parts: root (field text control, value/input/open models, form value,
  owner wiring), InputGroup (composes the caller's Input into the combobox
  control and anchors the popover), Trigger, Value, Popover.
- Closed-state metadata is planned from the slot tree, so filtering, the initial
  value label and form-value="text" work before the list has mounted.
- Selection text syncs on selection changes only, so allows-custom-value typing
  is not overwritten; read-only and disabled are injected onto the composed
  input because it reads the text-field protocol, not the field context.
- 24 baseline previews, the Chinese doc page, navigation, 19 behaviour tests and
  6 demo/document contracts. Async demo uses a local async source with abort,
  loading and incremental append (documented adaptations).

Not included: independent tarball consumption (B02d).
This commit is contained in:
maoyingjie
2026-10-25 16:59:16 +08:00
parent ff486fb665
commit 46e4df7e85
46 changed files with 4322 additions and 2 deletions
+1 -1
View File
@@ -24,7 +24,7 @@
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| combo-box | 已迁移(有已知差异) | ComboBox 五部件;24/24 基线例;可编辑输入 + 过滤 + 虚拟焦点、form-value key/text、menu-trigger 三态、多选 Value;见 B02 报告 |
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
@@ -249,3 +249,52 @@ export interface CollectionOwner extends CollectionView {
## 11. B02a 阶段复核通过
以 [B02a 阶段验收](B02a-acceptance.md) 为当前结论。集成人补齐静态空集合、嵌套控件按下状态及探针独立运行的 scrollTo 环境初始化;最新全套为 77 文件 / 1026 项,无未处理错误。仅放行 B02a,在当前任务分支连续完成 B02b、B02c、B02d,公共组件和完整示例尚未验收。
## 11. B02b:ComboBox 全部部件、文档与示例(已实现)
起点 `ff486fb`(含 B02a 验收 `B02a-acceptance.md`)。5 个部件、24 个基线示例、1 页中文文档、导航、19 项行为测试与 6 项演示/文档测试全部落地。**未做**独立产物消费(按四段安排在 B02d 统一完成)。
### 11.1 部件与映射
| 部件 | 实现要点 |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ComboBox` | 字段上下文(`kind: "text"`,`Label` 渲染 `<label for>`)、值/输入值/开关三套受控模型、集合 owner(`filter` / `virtualFocus` / `activeKey` / `keyboardIntent` / `isOpen`)、隐藏表单输入、`form-value` key/text |
| `ComboBoxInputGroup` | 组合调用方的 `Input`:注入 `role="combobox"`、`aria-expanded` / `-controls` / `-activedescendant` / `-autocomplete` / `-haspopup` / `-describedby`、`required`、`readonly`、`disabled`、值绑定与键盘处理;同时把它注册为弹层的 anchor |
| `ComboBoxTrigger` | 原生按钮、`data-open`、`tabindex=-1`(整个组合框只保留输入框一个 Tab 入口)、默认基线 chevron(展开时 CSS 旋转) |
| `ComboBoxValue` | 已选值文本(逗号连接)与 `data-placeholder`,支持作用域插槽 `{ isPlaceholder, selectedItems }` |
| `ComboBoxPopover` | 复用现有 `PopoverContent`(非模态、Teleport、外部点击、退出动画),`--trigger-width` / anchor point 变量,`onOpenAutoFocus` 阻止焦点进入弹层 |
**键盘与焦点所有权**:真实焦点始终在输入框;`ArrowDown/Up`、`Home/End`、`Enter`、`Escape`、`Tab` 与 IME(`isComposing` / `keyCode 229`)一律由组合体处理,集合在 `virtualFocus` 下不处理键盘、不移动 DOM 焦点、不提供 roving Tab;`aria-activedescendant` 指向真实挂载且可见的 option。
**关闭态元数据**:`metadata.ts` 的 `planComboBoxItems` 从插槽树收集 `ListBox` / `ListBoxItem`(含 `items` 驱动的渲染函数、`ListBoxSection`、`disabledKeys`),使关闭时也能过滤、显示初始值标签、解析 `form-value="text"`;`items` 属性优先,插槽计划不完整时回退到已挂载 registry。
### 11.2 示例与文档
24 个示例全部来自 `apps/docs/demos/combo-box-*.vue`,顺序与固定正文一致(default → full-width → with-description → required → disabled → with-disabled-options → with-sections → controlled → controlled-input-value → asynchronous-loading → default-selected-key → allows-custom-value → custom-indicator → custom-value → custom-filtering → render-function → menu-trigger → form-value → validation-behavior → custom-validation → read-only → multiple-selection → on-surface → custom-styles)。文档页 `apps/docs/components/combo-box.md` 含用法、组件结构、24 个预览、样式参考、5 个部件的 API 表与事件表、无障碍;导航加入 `pickers` 分类。
示例适配(逐项记录,未以占位替代):
1. `asynchronous-loading`:源示例请求 SWAPI;改为本地异步源(300ms、每查询一个 `AbortController`、加载中状态、`加载更多` 增量追加、空状态),状态机与源一致。
2. `ListBoxLoadMoreItem` 在本库不存在:用显式「加载更多」按钮 + `Spinner` 状态行替代(与既有 `select-asynchronous-loading` 同做法)。
3. `required` / `custom-validation`:源的 `alert` 改为页内 `role="status"` 文案(沿用 `select-required` 约定),仍读取真实 `FormData`。
4. `custom-value`:源示例本身没有 `ComboBox.Value`,保持同样的结构(选中项文本回写输入框)。
5. `render-function`:React `render` → 根元素 `as="div" data-custom="foo"`。
### 11.3 验证
- `pnpm typecheck` 通过;`pnpm test` **79 文件 / 1051 项**通过(新增 `tests/combo-box.test.ts` 19 项、`tests/combo-box-demos.test.ts` 6 项,均已加入 `test:unit`);`pnpm build:docs`、Prettier、`git diff --check` 通过。
- 行为测试覆盖:单一 combobox 节点与 `label for`、`aria-*` 连线、聚焦打开、输入过滤、Enter 确认并回写文本、Escape 关闭、IME 不确认、文本与选中不匹配时清除、`allows-custom-value` 保留输入、父级拒绝后仍未选中且可再次提案、外部改值同步、禁用 key 跳过、禁用不打开、只读不可改、多选值与过滤后保留已接受键、隐藏输入提交 key/text、`required` 原生阻止提交、Description/FieldError 进入 `aria-describedby`、`menu-trigger` 三态、触发器切换。
- 演示测试:预览清单与 24 个文件一一对应、无 `className`/`@gravity-ui/icons`/自绘 `<path>`、每个示例都渲染真实 combobox(含唯一 id 与 `aria-expanded`)、代表示例能打开并给出有效 `aria-activedescendant`、初始选中项的文本进入输入框、form-value 示例输出两个隐藏输入。
- 浏览器(5182,Chromium/IAB):24 个示例共 28 个 combobox;首个示例输入“猫”后 `expanded=true`、焦点仍在输入框、`aria-activedescendant` 指向 `role="option"` 的“猫”、列表 6 个 option 中 2 个可见(“猫”“熊猫”为包含匹配)、列表 `tabindex=-1`;`ArrowDown`+`Enter` 后输入框回写“猫”、列表关闭、焦点仍在输入;`Escape` 关闭并移除 `aria-activedescendant`;三个预选示例的输入框显示“猫”;禁用示例的输入框原生 `disabled`;`ComboBoxValue` 显示占位文本“未选择任何动物”;触发器 `tabindex=-1`;form-value 示例输出 `animal` / `animal-text` 隐藏输入。
### 11.4 本轮新增经验
- 关闭态的集合元数据必须由插槽计划提供:`ListBox` 未挂载时 registry 为空,过滤、初始标签与 `form-value="text"` 都会失效。
- 选中值的文本同步只能跟「选择变化」走,不能跟「输入值变化」走,否则 `allows-custom-value` 下用户输入会被立刻覆盖。
- 只读/禁用必须显式注入到组合出来的 `Input`(它读的是 `TextField` 上下文,不认 `fieldContextKey`)。
### 11.5 仍未验证
- 弹层内浮层选项的真实鼠标点击:本 IAB 会话对 floating 定位的 option 报 `not actionable`,改用键盘在页面验证,指针保焦点行为由 B02a 的 harness 与单测覆盖(记录为环境限制,未写成已通过)。
- 真实系统 IME、读屏软件、逐像素视觉对比。
- 独立 tarball 产物消费(B02d)。
+4
View File
@@ -208,3 +208,7 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/{tag,tag-group,error-message}`、`packages/styles/components/{tag,tag-group,error-message}.css`、`packages/styles/src/components/{tag,tag-group,error-message}/*.styles.ts`,中文 `(collections)/tag-group.mdx`、`(forms)/error-message.mdx` 与 `demos/cn/tag-group` 12 例、`demos/cn/error-message` 2 例。Tag 无独立文档页,按固定 tag-group 正文与示例迁移。
CSS/tv 仅加 `hv-` 前缀与 Vue 状态适配,保留 Apache-2.0 来源。TagRemoveButton 复用本库 CloseButton 与基线 CloseIcon,可访问名称为 `Remove tag {标签文本}`(固定基线测试的同一字符串)。上游 `TagGroup.List` / `Tag.RemoveButton` 在本库为具名导出 `TagGroupList` / `TagRemoveButton`;React `render` 函数对应 `as` / `as-child`;`useListData` 演示改为 Vue 响应式数组。RAC 的 `FieldSlotsGate`/`TextContext` 只在集合渲染时需要,Vue 端改用字段上下文与渲染期 id 规划,不移植该 gate。无新增依赖,未运行时依赖相邻 React 仓库。
## B02b ComboBox(2026-10-25)
固定 ce90ea3 的 `packages/react/src/components/combo-box/combo-box.tsx`、`packages/styles/components/combo-box.css`、`packages/styles/src/components/combo-box/combo-box.styles.ts`、中文 `(pickers)/combo-box.mdx` 与 `demos/cn/combo-box` 24 例。CSS/tv 仅加 `hv-` 前缀;默认 chevron 沿用基线 `icons.tsx` 路径。Vue 侧用选择/字段/弹层既有设施组合,未移植 RAC 的 `createCollectionSlot`(`InputGroup` 直接渲染容器并组合调用方的 `Input`),关闭态元数据由本批 `combo-box/metadata.ts` 从插槽树规划。示例的异步源、加载更多控件与 `alert` 适配已在报告 11.2 逐项记录,未运行时依赖相邻 React 仓库。
+9
View File
@@ -1017,3 +1017,12 @@ Tag/TagGroup/ErrorMessage 的最新验收见 [B03 复核记录](migrations/B03-r
## B02a 共享协议阶段(2026-10-25)
阶段复核见 [B02a 验收](migrations/B02a-acceptance.md)。过滤/虚拟焦点协议及真实受限虚拟窗口通过重点验证;静态空集合、嵌套按下状态和测试环境由集成人补齐。相关98项、全套1026项、类型/文档构建通过,无未处理错误。只允许继续B02b–d,不代表ComboBox/Autocomplete公共迁移完成。
## 2026-10-25 B02b ComboBox
部件、示例、文档与测试范围见 [B02 报告](migrations/B02-combobox-autocomplete.md) 第 11 节;本段只记录本轮实际命令与证据。
- `pnpm typecheck` 通过;`pnpm test` **79 文件 / 1051 项**通过;`pnpm build:docs`、Prettier、`git diff --check` 通过。
- 新增 `tests/combo-box.test.ts`(19 项行为)与 `tests/combo-box-demos.test.ts`(6 项文档/演示契约),均已加入 `test:unit`。
- 浏览器 5182(Chromium/IAB):输入过滤后焦点仍在输入框、`aria-activedescendant` 指向真实 option、列表只有一个 Tab 入口;`ArrowDown`+`Enter` 回写文本并关闭;`Escape` 移除 `aria-activedescendant`;三个预选示例输入框显示“猫”;禁用示例输入框原生禁用;`ComboBoxValue` 占位文本;form-value 输出 `animal` / `animal-text` 隐藏输入。
- 未验证:浮层选项的真实鼠标点击(本 IAB 对 floating option 报 `not actionable`,指针保焦点由 B02a harness 覆盖)、真实 IME、读屏软件、逐像素对比、独立 tarball 消费(B02d)。