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:
@@ -157,7 +157,7 @@ import {
|
||||
|
||||
<ComponentPreview name="combo-box-render-function" />
|
||||
|
||||
上游用 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 归属一致。
|
||||
|
||||
<ComponentPreview name="combo-box-form-value" />
|
||||
|
||||
@@ -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<string \| number> \| null` | - | 当前值(受控,`v-model`);多选时为 key 数组 |
|
||||
| `value` | `string \| number \| Array<string \| number> \| null` | - | 同 `model-value`(受控别名) |
|
||||
| `default-value` | `string \| number \| Array<string \| number> \| null` | - | 初始值(非受控);多选时为 key 数组 |
|
||||
| `selected-key` | `string \| number \| null` | - | 单选当前 key(受控别名) |
|
||||
| `default-selected-key` | `string \| number \| null` | - | 单选初始 key(非受控别名) |
|
||||
| `items` | `Array<{ id, textValue, isDisabled? }>` | - | 数据驱动渲染;不传时以 `ListBox` 的静态子项作为集合 |
|
||||
| `disabled-keys` | `Array<string \| number>` | - | 禁用项的 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<string \| number> \| null` | - | 当前值(受控,`v-model`);多选时为 key 数组 |
|
||||
| `value` | `string \| number \| Array<string \| number> \| null` | - | 同 `model-value`(受控别名) |
|
||||
| `default-value` | `string \| number \| Array<string \| number> \| null` | - | 初始值(非受控);多选时为 key 数组 |
|
||||
| `selected-key` | `string \| number \| null` | - | 单选当前 key(受控别名) |
|
||||
| `default-selected-key` | `string \| number \| null` | - | 单选初始 key(非受控别名) |
|
||||
| `items` | `Array<{ id, textValue, isDisabled? }>` | - | 数据驱动渲染;不传时以 `ListBox` 的静态子项作为集合 |
|
||||
| `disabled-keys` | `Array<string \| number>` | - | 禁用项的 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`)
|
||||
- 未实测读屏软件的变更播报与逐项读屏行为,因此不声称已通过该层验收
|
||||
|
||||
|
||||
Reference in New Issue
Block a user