diff --git a/apps/docs/components/autocomplete.md b/apps/docs/components/autocomplete.md index aac8354..c0c3578 100644 --- a/apps/docs/components/autocomplete.md +++ b/apps/docs/components/autocomplete.md @@ -205,7 +205,7 @@ Autocomplete 组件支持两种视觉变体: ### 表面样式 -在 [Surface](/components/surface) 组件内使用时,请使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体。 +在 [Surface](/components/surface) 组件内使用时,请使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体(根类名为 `.hv-autocomplete--secondary`;弹层内的 `SearchField` 需要时再单独声明自己的变体)。 @@ -319,30 +319,32 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co ### Autocomplete -| Prop | 类型 | 默认值 | 描述 | -| ------------------------- | ------------------------------------------------------------ | ------------------ | ----------------------------------------------------------------------------------- | -| `placeholder` | `string` | `'Select an item'` | 为空时显示的占位文本 | -| `selection-mode` | `'single' \| 'multiple'` | `'single'` | 单选或多选 | -| `allows-empty-collection` | `boolean` | `false` | 是否允许空集合 | -| `is-open` | `boolean` | - | 弹层打开状态(受控,`v-model:open` 亦可) | -| `default-open` | `boolean` | `false` | 弹层默认打开状态(非受控) | -| `disabled-keys` | `Array` | - | 禁用项的 key | -| `is-disabled` | `boolean` | `false` | 是否禁用 | -| `model-value` | `string \| number \| Array \| null` | - | 当前值(受控,`v-model`);多选时为 key 数组 | -| `value` | `string \| number \| Array \| null` | - | 同 `model-value`(受控别名) | -| `default-value` | `string \| number \| Array \| null` | - | 初始值(非受控);多选时为 key 数组 | -| `is-required` | `boolean` | `false` | 是否必填 | -| `is-invalid` | `boolean` | `false` | 值是否无效 | -| `name` | `string` | - | 表单提交字段名(输出隐藏输入,多选以逗号连接) | -| `form` | `string` | - | 关联的表单 id | -| `full-width` | `boolean` | `false` | 是否占满容器宽度 | -| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体:`primary` 为默认带阴影样式;`secondary` 为低强调无阴影,适用于 Surface 内 | -| `as` | `string` | `'div'` | 自定义根元素标签 | -| `as-child` | `boolean` | `false` | 使用唯一子元素作为根节点并合并属性 | -| `validate` | `(value) => string \| string[] \| true \| null \| undefined` | - | 校验函数;`native` 时提交会展示错误(上游无此 prop) | -| `validation-behavior` | `'native' \| 'aria'` | `'native'` | 原生校验阻止提交,或只用 ARIA 标记(上游无此 prop) | -| 默认插槽 | `{ isOpen, selectedKeys }` | - | 组件内容;作用域提供当前状态 | -| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | +| Prop | 类型 | 默认值 | 描述 | +| ------------------------- | ------------------------------------------------------------ | ------------------ | --------------------------------------------------------------------------------------------------- | +| `placeholder` | `string` | `'Select an item'` | 为空时显示的占位文本 | +| `selection-mode` | `'single' \| 'multiple'` | `'single'` | 单选或多选 | +| `allows-empty-collection` | `boolean` | `false` | 是否允许空集合 | +| `items` | `Array<{ id, textValue, isDisabled? }>` | - | 对应上游 `items: Iterable`:关闭态的已选文本与提交校验都取自它,不传时以 `ListBox` 子项为集合 | +| `disabled` | `boolean` | `false` | `is-disabled` 的等价别名 | +| `is-open` | `boolean` | - | 弹层打开状态(受控,`v-model:open` 亦可) | +| `default-open` | `boolean` | `false` | 弹层默认打开状态(非受控) | +| `disabled-keys` | `Array` | - | 禁用项的 key | +| `is-disabled` | `boolean` | `false` | 是否禁用 | +| `model-value` | `string \| number \| Array \| null` | - | 当前值(受控,`v-model`);多选时为 key 数组 | +| `value` | `string \| number \| Array \| null` | - | 同 `model-value`(受控别名) | +| `default-value` | `string \| number \| Array \| null` | - | 初始值(非受控);多选时为 key 数组 | +| `is-required` | `boolean` | `false` | 是否必填 | +| `is-invalid` | `boolean` | `false` | 值是否无效 | +| `name` | `string` | - | 表单提交字段名(输出隐藏输入,多选以逗号连接) | +| `form` | `string` | - | 关联的表单 id | +| `full-width` | `boolean` | `false` | 是否占满容器宽度 | +| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体:`primary` 为默认带阴影样式;`secondary` 为低强调无阴影,适用于 Surface 内 | +| `as` | `string` | `'div'` | 自定义根元素标签 | +| `as-child` | `boolean` | `false` | 把首个插槽元素当作根节点:保留其属性、事件、ref 与子节点,并合并根类名与 `data-slot="autocomplete"` | +| `validate` | `(value) => string \| string[] \| true \| null \| undefined` | - | 校验函数;`native` 时提交会展示错误(上游无此 prop) | +| `validation-behavior` | `'native' \| 'aria'` | `'native'` | 原生校验阻止提交,或只用 ARIA 标记(上游无此 prop) | +| 默认插槽 | `{ isOpen, selectedKeys }` | - | 组件内容;作用域提供当前状态 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | 事件: @@ -354,6 +356,8 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co | `openChange` | `boolean` | 弹层开关变化 | | `clear` | - | 清除已选值 | +提交层:单选输出一个同名条目,多选按每个 key 输出一个同名条目(`getAll(name)` 为数组);禁用项、被 `disabled-keys` 禁用以及已从集合删除的 key 不提交;集合从未提供过该 key(受控的关闭态值)时按调用方给出的值提交。`form` 同时作用于原生提交层与 reset 校验层。 + ### AutocompleteTrigger | Prop | 类型 | 默认值 | 描述 | @@ -387,7 +391,7 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co | 默认插槽 | `Component` | - | 自定义清除图标 | | `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | -`aria-label` 默认 `Clear selection`,`tabindex="-1"`,无选择时 `data-empty="true"` 并隐藏。 +`aria-label` 默认 `Clear selection`,`tabindex="-1"`,无选择时 `data-empty="true"` 并隐藏。调用方 `click` 处理器先执行:它调用 `preventDefault()` 时内部清除被取消;原生 `disabled` 与根上的禁用状态任一成立都会禁用按钮并跳过清除。 `@click` 与内部清除处理会合并执行(Vue 事件数组);模板 ref 通过 `defineExpose` 暴露组件实例,需要 DOM 时取 `$el`。 @@ -415,7 +419,7 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co | 默认插槽 | `Component` | - | 必须包含 `SearchField`(内含 `SearchFieldInput`)与 `ListBox` | | `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | -过滤文本由 `AutocompleteFilter` 拥有,并通过集合的过滤协议影响列表的显示与键盘导航;它不会清除已接受的选择。 +过滤文本由 `AutocompleteFilter` 拥有,并通过集合的过滤协议影响列表的显示与键盘导航;它不会清除已接受的选择。组合输入期间列表保持原样,`compositionend` 后再提交一次过滤;会话内的 `Enter` 不确认选择。 受控文本用 `:input-value` + `@input-change`(或 `v-model:input-value`): @@ -441,7 +445,7 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co 上游页面导出的 `useFilter` hook(`contains` / `startsWith` / `endsWith` 与 `sensitivity`)在本库没有对应导出。替代方式: -- `AutocompleteFilter` 的默认谓词等价于 `useFilter({ sensitivity: "base" }).contains`(不区分大小写的包含匹配) +- `AutocompleteFilter` 的默认谓词等价于 `useFilter({ sensitivity: "base" }).contains`:按 `ConfigProvider` 的 locale 折叠大小写与变音符号,`cafe` 能命中 `Café` - 需要 `startsWith` / `endsWith` 等语义时,直接给 `:filter="(text, input) => …"` 传函数 - 数据源或调用方已过滤时(异步、虚拟化示例),传 `:filter="() => true"` 避免二次过滤 diff --git a/apps/docs/components/combo-box.md b/apps/docs/components/combo-box.md index 5a6ffac..ae34a3e 100644 --- a/apps/docs/components/combo-box.md +++ b/apps/docs/components/combo-box.md @@ -157,7 +157,7 @@ import { -上游用 React `render` 函数替换根 DOM 元素;Vue 中对应 `as`(自定义根元素标签)与 `as-child`(自定义组件作为唯一根),示例通过根元素属性演示同一能力。 +上游用 React `render` 函数替换根 DOM 元素;Vue 中对应 `as`(自定义根元素标签)与 `as-child`(把首个插槽元素当作根节点)。`as-child` 时该元素保留自己的属性、事件、ref 与子节点,并额外获得根类名与 `data-slot="combo-box"`,其余部件渲染在它内部;`a` 之外的可聚焦性由调用方负责。 ### 菜单触发方式 @@ -171,7 +171,9 @@ import { ### 表单值 -使用 `form-value` 控制提交表单时提交选中项的 key 还是文本。默认值为 `key`;`allows-custom-value` 为真时始终提交文本。多选时多个值以英文逗号连接。 +使用 `form-value` 控制提交表单时提交选中项的 key 还是文本。默认值为 `key`;`allows-custom-value` 为真时始终提交当前输入文本。 + +提交层遵循本库选择类字段的统一约定:单选输出一个同名条目,多选按每个 key 输出一个同名条目(`FormData.getAll(name)` 得到数组,不再拼成逗号串);禁用或被 `disabled-keys` 禁用的项、以及从集合中删除的项都不提交;没有任何可提交值时整个字段不出现在 `FormData` 中。`form` 同时作用于可见输入与提交层,因此外部表单的校验与 reset 归属一致。 @@ -276,43 +278,44 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he ### ComboBox -| Prop | 类型 | 默认值 | 描述 | -| ------------------------- | ------------------------------------------------------------ | ------------------ | --------------------------------------------------------------------------------------------- | -| `input-value` | `string` | - | 当前输入值(受控,可用 `v-model:input-value`) | -| `default-input-value` | `string` | `''` | 默认输入值(非受控) | -| `selection-mode` | `'single' \| 'multiple'` | `'single'` | 单选或多选 | -| `model-value` | `string \| number \| Array \| null` | - | 当前值(受控,`v-model`);多选时为 key 数组 | -| `value` | `string \| number \| Array \| null` | - | 同 `model-value`(受控别名) | -| `default-value` | `string \| number \| Array \| null` | - | 初始值(非受控);多选时为 key 数组 | -| `selected-key` | `string \| number \| null` | - | 单选当前 key(受控别名) | -| `default-selected-key` | `string \| number \| null` | - | 单选初始 key(非受控别名) | -| `items` | `Array<{ id, textValue, isDisabled? }>` | - | 数据驱动渲染;不传时以 `ListBox` 的静态子项作为集合 | -| `disabled-keys` | `Array` | - | 禁用项的 key | -| `open` / `is-open` | `boolean` | - | 弹层打开状态(受控,可用 `v-model:open`) | -| `default-open` | `boolean` | `false` | 弹层默认打开状态(非受控) | -| `default-filter` | `(text: string, inputValue: string) => boolean` | 包含匹配 | 自定义过滤函数 | -| `is-disabled` | `boolean` | `false` | 是否禁用 | -| `is-read-only` | `boolean` | `false` | 只读:值可聚焦但不可修改 | -| `is-required` | `boolean` | `false` | 是否必填 | -| `is-invalid` | `boolean` | `false` | 值是否无效 | -| `validate` | `(value) => string \| string[] \| true \| null \| undefined` | - | 校验函数;`validation-behavior="native"` 时提交会展示错误,实时校验请改用 `is-invalid` | -| `validation-behavior` | `'native' \| 'aria'` | `'native'` | 原生校验阻止提交,或只用 ARIA 标记 | -| `name` | `string` | - | 表单提交时的字段名(输出隐藏输入) | -| `form` | `string` | - | 关联的表单 id | -| `form-value` | `'key' \| 'text'` | `'key'` | 提交 key 还是文本;`allows-custom-value` 时始终提交文本 | -| `auto-complete` | `string` | `'off'` | 输入框 `autocomplete` | -| `auto-focus` | `boolean` | `false` | 挂载时聚焦 | -| `allows-custom-value` | `boolean` | `false` | 允许输入不在列表中的值 | -| `allows-empty-collection` | `boolean` | `false` | 无匹配项时仍可打开弹层 | -| `menu-trigger` | `'focus' \| 'input' \| 'manual'` | `'focus'` | 打开弹层的交互方式 | -| `should-focus-wrap` | `boolean` | `false` | 方向键是否在首尾循环 | -| `full-width` | `boolean` | `false` | 是否占满容器宽度 | -| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体:`primary` 为默认带阴影样式;`secondary` 为低强调无阴影,适用于 Surface 内 | -| `placeholder` | `string` | `'Select an item'` | `ComboBoxValue` 的缺省占位文本(上游根上没有该 prop,由 `ComboBoxValue` 的 placeholder 表达) | -| `as` | `string` | `'div'` | 自定义根元素标签 | -| `as-child` | `boolean` | `false` | 使用唯一子元素作为根节点并合并属性 | -| 默认插槽 | `{ isOpen, inputValue, selectedKey, selectedKeys }` | - | 组件内容;作用域提供当前状态 | -| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | +| Prop | 类型 | 默认值 | 描述 | +| ------------------------- | ------------------------------------------------------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `input-value` | `string` | - | 当前输入值(受控,可用 `v-model:input-value`) | +| `default-input-value` | `string` | `''` | 默认输入值(非受控) | +| `selection-mode` | `'single' \| 'multiple'` | `'single'` | 单选或多选 | +| `model-value` | `string \| number \| Array \| null` | - | 当前值(受控,`v-model`);多选时为 key 数组 | +| `value` | `string \| number \| Array \| null` | - | 同 `model-value`(受控别名) | +| `default-value` | `string \| number \| Array \| null` | - | 初始值(非受控);多选时为 key 数组 | +| `selected-key` | `string \| number \| null` | - | 单选当前 key(受控别名) | +| `default-selected-key` | `string \| number \| null` | - | 单选初始 key(非受控别名) | +| `items` | `Array<{ id, textValue, isDisabled? }>` | - | 数据驱动渲染;不传时以 `ListBox` 的静态子项作为集合 | +| `disabled-keys` | `Array` | - | 禁用项的 key | +| `open` / `is-open` | `boolean` | - | 弹层打开状态(受控,可用 `v-model:open`) | +| `default-open` | `boolean` | `false` | 弹层默认打开状态(非受控) | +| `default-filter` | `(text: string, inputValue: string) => boolean` | 不区分大小写与重音的包含匹配 | 自定义过滤函数;默认谓词按 `ConfigProvider` 的 locale 折叠大小写与变音符号(`Café` 可由 `cafe` 命中) | +| `is-disabled` | `boolean` | `false` | 是否禁用 | +| `disabled` | `boolean` | `false` | `is-disabled` 的等价别名 | +| `is-read-only` | `boolean` | `false` | 只读:值可聚焦但不可修改 | +| `is-required` | `boolean` | `false` | 是否必填 | +| `is-invalid` | `boolean` | `false` | 值是否无效 | +| `validate` | `(value) => string \| string[] \| true \| null \| undefined` | - | 校验函数;`validation-behavior="native"` 时提交会展示错误,实时校验请改用 `is-invalid` | +| `validation-behavior` | `'native' \| 'aria'` | `'native'` | 原生校验阻止提交,或只用 ARIA 标记 | +| `name` | `string` | - | 表单提交时的字段名(输出隐藏输入) | +| `form` | `string` | - | 关联的表单 id | +| `form-value` | `'key' \| 'text'` | `'key'` | 提交 key 还是文本;`allows-custom-value` 时始终提交文本 | +| `auto-complete` | `string` | `'off'` | 输入框 `autocomplete` | +| `auto-focus` | `boolean` | `false` | 挂载时聚焦 | +| `allows-custom-value` | `boolean` | `false` | 允许输入不在列表中的值 | +| `allows-empty-collection` | `boolean` | `false` | 无匹配项时仍可打开弹层 | +| `menu-trigger` | `'focus' \| 'input' \| 'manual'` | `'focus'` | 打开弹层的交互方式 | +| `should-focus-wrap` | `boolean` | `false` | 方向键是否在首尾循环 | +| `full-width` | `boolean` | `false` | 是否占满容器宽度 | +| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体:`primary` 为默认带阴影样式;`secondary` 为低强调无阴影,适用于 Surface 内。根上的取值由内部 `Input` 继承,`Input` 自己显式设置时以子控件为准 | +| `placeholder` | `string` | `'Select an item'` | `ComboBoxValue` 的缺省占位文本(上游根上没有该 prop,由 `ComboBoxValue` 的 placeholder 表达) | +| `as` | `string` | `'div'` | 自定义根元素标签 | +| `as-child` | `boolean` | `false` | 使用唯一子元素作为根节点并合并属性 | +| 默认插槽 | `{ isOpen, inputValue, selectedKey, selectedKeys }` | - | 组件内容;作用域提供当前状态 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | 事件: @@ -381,6 +384,8 @@ ComboBox 实现 ARIA combobox 模式: - 中文输入法组合期间不确认选择(`isComposing` / `keyCode 229` 时忽略键盘提交) - 过滤不会清除已接受的选择;被过滤掉的已选项仍保留标签 - 弹层内不出现第二个 Tab 入口,关闭后移除 `aria-activedescendant` +- 组合输入期间保留已经渲染的行,直到 `compositionend` 才提交一次过滤;会话内的 `Enter` 不会确认选择(同时检查会话状态、`isComposing` 与 `keyCode 229`) +- 必填只由校验阻止无效提交,不阻止用户把值编辑为空;`native` 与 `aria` 两种校验都按同一份约束判断 - 支持禁用状态(`is-disabled` / `disabled-keys`)、输入过滤式搜索、与原生表单集成(`name` / `form` / `form-value`)与自定义值(`allows-custom-value`) - 未实测读屏软件的变更播报与逐项读屏行为,因此不声称已通过该层验收 diff --git a/docs/migrations/B02-combobox-autocomplete.md b/docs/migrations/B02-combobox-autocomplete.md index a1a944b..46928c4 100644 --- a/docs/migrations/B02-combobox-autocomplete.md +++ b/docs/migrations/B02-combobox-autocomplete.md @@ -460,3 +460,94 @@ export interface CollectionOwner extends CollectionView { - `pnpm typecheck` 通过;`pnpm test` **81 文件 / 1078 项**通过(新增 5 项:ComboBox 自定义值回车两例、两族 `data-slot` 契约、Autocomplete 示例搜索框壳层契约);`pnpm build:docs`、`pnpm build:playground`、`pnpm format`、`git diff --check` 通过。 - 编译 CSS 证据见 13.5,取自 `pnpm build:docs` 产物。 - 浏览器复验本轮**未完成**:IAB 在 `Page.enable`(20s)与 `Runtime.evaluate`(10s)上连续超时,`browser.tabs.new()` 返回 `renderer timed out handling IAB create`;`agent.browsers.list()` 只有 IAB 一个后端,没有扩展 Chrome 可切换。因此本轮不声称已完成浏览器视觉复验;§12.3 记录的上一轮结果仍有效,但那一轮早于本轮 CSS 与自定义值修复。待 IAB 恢复后需补验三项:触发器图标打开后 180° 旋转、弹层搜索框 `secondary` 变体无阴影、自定义值回车后的展示与关闭。 + +## 14. 整批退回返修(评审 R1–R10) + +评审以 `/private/tmp/B02-public-review.md` 与 30 项探针退回 B02b/B02c,指出 5 个 P1、4 个 P2 与 B02d 未完成。探针原文已固化为 `tests/b02-review.probe.test.ts`(已加入 `test:unit`),修复前 29 项失败、1 项通过,修复后 30 项全部通过。以下逐项记录"问题 → 实现位置 → 回归"。 + +### 14.1 R1 原生清除按钮永远提前返回(P1) + +`AutocompleteClearButton` 先 `preventDefault()` 再判断 `event.defaultPrevented`,原生可取消 click 因此从不调用 `ctx.clear()`;旧测试用不可取消的 `MouseEvent` 掩盖了它。 + +修复:先尊重调用方取消,再 `preventDefault` + `stopPropagation`,最后执行唯一清除路径;调用方 `disable` 与根禁用任一成立时跳过。回归:探针用真实 `.click()`;`tests/autocomplete.test.ts` 新增"调用方 `preventDefault` 时不清除"。浏览器 5182:真实点击某示例("州(受控)")的清除按钮后值回到占位符「选择一个州」,按钮转为 `data-empty`。 + +### 14.2 R2 表单与字段协议(P1) + +原实现只输出一个 `value=逗号串` 的隐藏 `input`,`isDisabled`、`disabled-keys`、删除项、`form` 归属都不成立。现在两族改为复用本库选择类字段的统一提交层(`choice/shared.ts` 的 `selectionInputs`): + +- 每个可提交 key 一个同名隐藏条目,`getAll(name)` 得到数组,含逗号的 key 不再被破坏; +- 禁用字段不渲染提交层;被 `disabled-keys` 禁用的 key 不提交; +- 曾经出现在集合里、随后被删除的 key 不提交(按"seen"集合判断);从未列出的 key(受控关闭态值)按调用方给出的值提交;`Autocomplete.items` 同理; +- `ComboBox` 的 `form` 同时落到可见 `Input`(`input().form === 外部表单`)与提交层,`useChoiceForm` 与原生层共用同一归属; +- `allowsCustomValue` 的 `form-value` 恒为当前输入文本(选中 Alpha 后再输入 Custom animal,提交 `Custom animal`); +- `request([])` 不再因 `isRequired` 被拦,必填只由校验阻止无效提交。 + +回归:探针 6 项;`tests/combo-box.test.ts` 新增必填可清空 + `checkValidity() === false`、外部表单 `form` 关联与 reset/取消 reset、禁用字段无提交层;`tests/autocomplete.test.ts` 新增多值同名条目 + 禁用无提交;两个 demo 契约测试改为先选择再断言 `FormData`(空状态不再输出空条目)。 + +### 14.3 R3 ComboBox 输入同步(P1) + +旧 `watch` 用 `keys.map(String).join()` + `records.length` 作依赖,且无选中项时直接 return,`displayInputValue` 又把空文本回退成旧标签。现在:选择身份按 `typeof key` 编码(`0` 与 `"0"` 不再混同),依赖同时包含选中项的 `textValue`(同长度替换也同步),受控 `inputValue` 优先(显式 `""` 显示为空),非受控文本由"接受的选择"驱动,输入清空选择时用一次性 `keepDraft` 保住草稿,`allowsCustomValue` 的草稿在无记录时不被覆盖。表单 reset 后重新取回选中项标签。 + +回归:探针 5 项(外部清空、数字/字符串 key、同长度标签更新、受控空文本、必填清空)+ 既有 SSR 首屏标签用例。 + +### 14.4 R4 组合输入(P1) + +两族此前一边保存 `composing` 一边照常过滤;ComboBox 的 `keydown` 也没检查会话状态。现在:过滤文本 `filterText` 与会话分离,组合期间保留已渲染行,`compositionend` 后统一提交一次过滤与"文本不再匹配已选值"的判断;`keydown` 同时检查会话、`event.isComposing` 与 `keyCode 229`。 + +回归:探针 3 项(未标记 `isComposing` 的 Enter、两族组合期间不过滤)+ 两族 `compositionstart → input → compositionend` 的完整序列。 + +### 14.5 R5 受控关闭被拒后抢焦点(P1) + +`request()` 在选择后无条件 `nextTick` 聚焦触发器,`setOpen(false)` 也立刻清理活动项。现在焦点恢复与活动项清理都移入"关闭被接受"的分支(`nextTick` 后检查 `open.value`),拒绝关闭时保留焦点、`aria-expanded` 与活动行。 + +回归:探针(父级拒绝关闭后 `aria-expanded` 仍为 `true`、焦点仍在搜索框)。浏览器 5182 补验:搜索框按 `Tab` 后弹层关闭且焦点落在弹层外的按钮(不回跳触发器);点击页面标题后弹层关闭、焦点留在被点击的标题上。 + +### 14.6 R6 组合输入覆盖 ref / ARIA / 原生禁用(P2) + +- `cloneVNode` 会替换 `ref`,且 Vue 3.5 把组件 ref 存进 `{ i, r }` 持有者。新增 `mergedRef`(`combo-box/dom.ts`)同时保留调用方模板 ref 与内部节点,`Input`/`SearchFieldInput` 都改用合并 ref。 +- `AutocompleteFilter` 不再无条件写根的 `aria-label`/`aria-labelledby`/`aria-describedby`:搜索输入自己声明时以它为准。 +- `AutocompleteClearButton` 与 `ComboBoxTrigger` 合并调用方 `disabled` 属性,点击守卫同样读取合并后的禁用。 + +回归:探针 5 项(两个 ref、搜索框名称、两处 `disabled`)+ 清除按钮取消用例;`combo-box.test.ts` 覆盖 `asChild` 宿主上的事件与 ref。 + +### 14.7 R7 声明了但未生效的公开参数(P2) + +- `asChild`:根节点改为"根元素拥有 Popover",两族都支持把首个插槽元素当根:保留其属性、事件、ref、子节点,并合并根类名与 `data-slot`;其余部件渲染在它内部。替换 `children` 时同步修正 `shapeFlag`(否则文本子节点会渲染成 `[object Object]`)。 +- `autoFocus`:挂载后聚焦组合输入,禁用字段跳过。 +- `ComboBox.variant`:由根继承到内部 `Input`(`hv-input--secondary`),`Input` 自己显式声明时以子控件为准。上游该 prop 只进入 context 未被消费,这里按文档语义落地并记录。 + +浏览器 5182:`on-surface` 示例的输入为 `hv-input--secondary`、`box-shadow` 全零;`asChild`/`autoFocus` 由 jsdom 用例覆盖。 + +### 14.8 R8 过滤国际化(P2) + +新增 `collection/match.ts` 的 `createBaseContains(locale)`:NFKD 分解 + 去组合记号 + `toLocaleLowerCase`,按 `ConfigProvider` 的 locale 折叠大小写与变音符号。两族默认谓词改用它,`default-filter` / `filter` 仍完全接管。 + +回归:`Café` ← `cafe` / `CAFÉ` / 分解形式 `cafe\u0301`;自定义谓词优先级(自定义 `defaultFilter` 被调用且结果生效)。 + +### 14.9 R9 Autocomplete 指示器选择器不可达(P2) + +上游把指示器类名、`data-slot="autocomplete-default-indicator"` 与 `data-open` 放在**同一个元素**(默认图标 svg)上,本库把它们拆在外层 span 与内层 svg。现在默认图标与自定义图标都由图标元素本身承载类名、`data-slot`(自定义时用 `autocomplete-indicator`)与 `data-open`,外层 span 退化为 `autocomplete-indicator-wrapper`。 + +浏览器 5182 实测:`.hv-autocomplete__indicator[data-slot="autocomplete-default-indicator"]` 命中 1 个元素,计算尺寸 `16px × 16px`,展开时 `rotate: 180deg`。 + +### 14.10 R10 与 B02d 收尾 + +- `Autocomplete.items`(对应上游 `items: Iterable`)已实现:驱动关闭态已选文本、`selectedItems` 与提交校验。 +- 新增公开插槽状态类型 `ComboBoxState` / `ComboBoxValueState` / `AutocompleteState` / `AutocompleteValueState`、`AutocompleteItem` 与 `CollectionKey`,配合 `tests/package/b02-pickers-contract.ts` 的正反例。 +- 修掉一个真实导出缺陷:`ComboBoxValue as ComboBoxValueType` 与组件 `ComboBoxValue` 同名,消费端同时导入两者时 TypeScript 会把类型别名解析成值;模型类型改为独立导出的 `ComboBoxModelValue`。 + +### 14.11 本轮命令与结果 + +- `pnpm typecheck` 通过。 +- `pnpm test`:**82 文件 / 1123 项**通过(`b02-review` 探针 30 项全部通过;两族新增 21 项补充回归)。 +- `pnpm test:unit`:72 文件 / 1087 项通过(探针已加入清单)。 +- `pnpm build:docs`、`pnpm build:playground`、`pnpm format`、`git diff --check` 通过。 +- 独立产物消费(`/private/tmp/heroui-b02-consumer`,两份 `pnpm pack` tarball + `pnpm-workspace.yaml` override):`node consume-b02-pickers.mjs` 通过(导出、SSR HTML 契约、CSS 选择器、变体函数);`tsc --strict --skipLibCheck` 在 `--module nodenext --moduleResolution nodenext` 与 `--module esnext --moduleResolution bundler` 两种模式下对 `b02-pickers-contract.ts` 均通过,`@ts-expect-error` 反例全部生效。 +- 浏览器 5182(Chromium/IAB)复核:真实点击清除按钮生效;指示器与触发器图标同为 16px、展开旋转 180°;`on-surface` 输入为 `secondary` 无阴影;自定义值回车后文本保留并关闭(值写入由 jsdom 用例断言);`Tab` 与外部点击都不会回跳触发器。 + +### 14.12 仍未验证 + +- 真实系统输入法、读屏软件、逐像素视觉对比:仍只验证组合事件与状态协议。 +- 独立消费工程里的**浏览器** ESM/CSS 运行(本轮只做了 node ESM + SSR + CSS 文本断言,浏览器仍不可用时不声称)。 +- 弹层内浮层选项的真实鼠标点击(IAB 对 floating option 报 `not actionable`)、嵌套 Modal 内逐层 `Escape`、快速重开。 +- `ComboBox.variant` 上游只进入 context 未消费,本库按文档语义实现,属记录在案的适配差异。 diff --git a/docs/verification.md b/docs/verification.md index 93fa042..4a86238 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -1043,3 +1043,13 @@ Tag/TagGroup/ErrorMessage 的最新验收见 [B03 复核记录](migrations/B03-r - `pnpm typecheck` 通过;`pnpm test` **81 文件 / 1078 项**通过(比 B02c 多 5 项:ComboBox 自定义值回车两例、两族 `data-slot` 契约、Autocomplete 示例搜索框壳层契约);`pnpm build:docs`、`pnpm build:playground`、`pnpm format`、`git diff --check` 通过。 - 编译产物证据(`pnpm build:docs` 输出 `apps/docs/.vitepress/dist/assets/style.*.css`):`data-slot` 属性值已全部去掉误加的 `hv-` 前缀,`data-slot="hv-` 计数为 0;存在 `.hv-combo-box__trigger[data-open=true] [data-slot=combo-box-trigger-default-icon]{rotate:180deg}`、`.hv-autocomplete__indicator[data-slot=autocomplete-default-indicator]`(1rem)与 `.hv-autocomplete__clear-button [data-slot=autocomplete-clear-button-icon]`(0.875rem)。 - 浏览器复验本轮未完成:IAB 在 `Page.enable`(20s)与 `Runtime.evaluate`(10s)连续超时,`tabs.new()` 报 `renderer timed out handling IAB create`,`agent.browsers.list()` 仅有 IAB 一个后端、无扩展 Chrome 可切换。因此本轮不声称已完成浏览器视觉复验;B02b/B02c 那两轮的浏览器结果仍有效,但早于本轮 CSS 与自定义值修复,待 IAB 恢复后需补验触发器图标旋转、弹层搜索框 secondary 变体与自定义值展示。 + +## 2026-10-25 B02 整批退回返修(评审 R1–R10) + +逐项映射见 [B02 报告](migrations/B02-combobox-autocomplete.md) 第 14 节;本段只记录本轮命令与证据。 + +- 探针固化:`tests/b02-review.probe.test.ts`(30 项,已加入 `test:unit`)。修复前 29 失败 / 1 通过,修复后 30 通过。 +- `pnpm typecheck` 通过;`pnpm test` **82 文件 / 1123 项**通过;`pnpm test:unit` 72 文件 / 1087 项通过;`pnpm build:docs`、`pnpm build:playground`、`pnpm format`、`git diff --check` 通过。 +- 独立产物消费:`/private/tmp/heroui-b02-consumer` 用两份新 tarball 安装,`node consume-b02-pickers.mjs` 通过;`b02-pickers-contract.ts` 在 NodeNext 与 bundler 两种解析模式下 tsc 通过(含 `@ts-expect-error` 反例)。 +- 浏览器 5182(Chromium/IAB):原生点击清除按钮后值回到占位符;指示器与 ComboBox 触发器图标计算尺寸 16px、展开时 `rotate: 180deg`;`on-surface` 输入类名为 `hv-input--secondary` 且 `box-shadow` 全零;自定义值输入后回车文本保留并关闭;搜索框 `Tab` 与页面外部点击都不会把焦点抢回触发器。 +- 未验证:真实系统输入法、读屏软件、逐像素对比、独立工程内的浏览器 ESM/CSS 运行、浮层选项真实鼠标点击、嵌套 Modal 逐层 Escape、快速重开。 diff --git a/package.json b/package.json index d37d0a0..9b2cf24 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build", "typecheck": "vue-tsc --noEmit", "test": "vitest run", - "test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/b01-menu-dropdown.test.ts tests/b01-review.probe.test.ts tests/b01-complete-review.probe.test.ts tests/cssom.test.ts tests/tag-error-message.test.ts tests/collection-filter-virtual.test.ts tests/b02a-review.probe.test.ts tests/b02a-round2-review.probe.test.ts tests/combo-box.test.ts tests/combo-box-demos.test.ts tests/autocomplete.test.ts tests/autocomplete-demos.test.ts", + "test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/b01-menu-dropdown.test.ts tests/b01-review.probe.test.ts tests/b01-complete-review.probe.test.ts tests/cssom.test.ts tests/tag-error-message.test.ts tests/collection-filter-virtual.test.ts tests/b02a-review.probe.test.ts tests/b02a-round2-review.probe.test.ts tests/b02-review.probe.test.ts tests/combo-box.test.ts tests/combo-box-demos.test.ts tests/autocomplete.test.ts tests/autocomplete-demos.test.ts", "test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts", "format": "prettier --check .", "format:fix": "prettier --write .", diff --git a/packages/vue/src/components/autocomplete/Autocomplete.vue b/packages/vue/src/components/autocomplete/Autocomplete.vue index ec21456..3e5e614 100644 --- a/packages/vue/src/components/autocomplete/Autocomplete.vue +++ b/packages/vue/src/components/autocomplete/Autocomplete.vue @@ -1,9 +1,11 @@