fix(pickers): rework B02 against the public review

Restore native clearing, unify the form/field protocol with the other choice
families (per-key entries, disabled and removed keys omitted, shared form
owner), synchronise ComboBox text by key identity, keep filtering out of open
composition sessions, and stop stealing focus when a controlled close is
rejected. Also merge caller refs/ARIA/disabled, implement asChild, autoFocus
and ComboBox variant, use a locale-aware base matcher, and put the indicator
class and slot on the icon element the ported CSS selects.
This commit is contained in:
maoyingjie
2026-10-25 20:40:24 +08:00
parent 3e9be13b19
commit e34b9debdf
24 changed files with 1808 additions and 236 deletions
+32 -28
View File
@@ -205,7 +205,7 @@ Autocomplete 组件支持两种视觉变体:
### 表面样式
在 [Surface](/components/surface) 组件内使用时,请使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体。
在 [Surface](/components/surface) 组件内使用时,请使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体(根类名为 `.hv-autocomplete--secondary`;弹层内的 `SearchField` 需要时再单独声明自己的变体)。
<ComponentPreview name="autocomplete-on-surface" />
@@ -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<string \| number>` | - | 禁用项的 key |
| `is-disabled` | `boolean` | `false` | 是否禁用 |
| `model-value` | `string \| number \| Array<string \| number> \| null` | - | 当前值(受控,`v-model`);多选时为 key 数组 |
| `value` | `string \| number \| Array<string \| number> \| null` | - | 同 `model-value`(受控别名) |
| `default-value` | `string \| number \| Array<string \| number> \| 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<T>`:关闭态的已选文本与提交校验都取自它,不传时以 `ListBox` 子项为集合 |
| `disabled` | `boolean` | `false` | `is-disabled` 的等价别名 |
| `is-open` | `boolean` | - | 弹层打开状态(受控,`v-model:open` 亦可) |
| `default-open` | `boolean` | `false` | 弹层默认打开状态(非受控) |
| `disabled-keys` | `Array<string \| number>` | - | 禁用项的 key |
| `is-disabled` | `boolean` | `false` | 是否禁用 |
| `model-value` | `string \| number \| Array<string \| number> \| null` | - | 当前值(受控,`v-model`);多选时为 key 数组 |
| `value` | `string \| number \| Array<string \| number> \| null` | - | 同 `model-value`(受控别名) |
| `default-value` | `string \| number \| Array<string \| number> \| 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"` 避免二次过滤