fix(pickers): repair data-slot selectors and align demos with the baseline
The CSS port prefixed data-slot attribute values with hv-, so the compiled selectors never matched the DOM and the ComboBox trigger chevron never rotated. Only class names get the prefix; slot values stay byte-identical. Also commit typed text as the value when allowsCustomValue finds no record, restore the baseline search-field shell in all 24 Autocomplete demos, and correct both doc pages against the pinned upstream sources.
This commit is contained in:
@@ -77,15 +77,17 @@ import {
|
||||
<ComboBoxPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="news" text-value="资讯">
|
||||
资讯
|
||||
<Label>资讯</Label>
|
||||
<Description>最新消息</Description>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxSection>
|
||||
<Header>更多</Header>
|
||||
<ListBoxItem id="travel" text-value="旅行">旅行</ListBoxItem>
|
||||
<ListBoxItem id="travel" text-value="旅行">
|
||||
<Label>旅行</Label>
|
||||
</ListBoxItem>
|
||||
</ListBoxSection>
|
||||
</ListBox>
|
||||
<Separator />
|
||||
</ComboBoxPopover>
|
||||
</ComboBox>
|
||||
</template>
|
||||
@@ -159,11 +161,11 @@ import {
|
||||
|
||||
### 菜单触发方式
|
||||
|
||||
使用 `menu-trigger` 控制弹层何时打开:
|
||||
使用 `menu-trigger` prop 控制 Popover 何时打开:
|
||||
|
||||
- `focus`(默认):输入框获得焦点时打开
|
||||
- `input`:用户编辑输入文本时打开
|
||||
- `manual`:仅当按下触发按钮或使用方向键时打开
|
||||
- `focus`(默认):输入框获得焦点时打开 Popover
|
||||
- `input`:用户编辑输入文本时打开 Popover
|
||||
- `manual`:仅当用户按下触发按钮或使用方向键时打开 Popover
|
||||
|
||||
<ComponentPreview name="combo-box-menu-trigger" />
|
||||
|
||||
@@ -196,13 +198,13 @@ import {
|
||||
|
||||
### 多选
|
||||
|
||||
设置 `selection-mode="multiple"` 允许选择多个选项。多选时用 `ComboBoxValue` 展示已选项,并同时给内部 `ListBox` 传 `selection-mode="multiple"`。值通过 `v-model` / `default-value`(数组)以及 `@selection-change` 控制。
|
||||
设置 `selection-mode="multiple"` 以允许选择多个选项。在多选模式下,使用 `ComboBoxValue` 展示已选项,并同时给内部的 `ListBox` 传入 `selection-mode="multiple"`。选择通过 `v-model` / `default-value`(数组)以及 `@change`(或 `@update:model-value`)控制;`@selection-change` 在多选下只携带首个 key,数组请用前两者。
|
||||
|
||||
<ComponentPreview name="combo-box-multiple-selection" />
|
||||
|
||||
### 表面样式
|
||||
|
||||
在 Surface 内使用时,请使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体。
|
||||
在 [Surface](/components/surface) 内使用时,请使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体。
|
||||
|
||||
<ComponentPreview name="combo-box-on-surface" />
|
||||
|
||||
@@ -215,6 +217,7 @@ import {
|
||||
### 全局 CSS
|
||||
|
||||
可使用 `@layer components` 指令自定义 ComboBox 组件类。
|
||||
[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
@@ -273,57 +276,63 @@ 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`) |
|
||||
| `value` | `string \| number \| Array \| null` | - | 同 `model-value`(受控别名) |
|
||||
| `default-value` | `string \| number \| Array \| null` | - | 初始值(非受控) |
|
||||
| `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 |
|
||||
| `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' \| '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'` | 视觉变体 |
|
||||
| `placeholder` | `string` | - | `ComboBoxValue` 的缺省占位文本 |
|
||||
| `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` | 包含匹配 | 自定义过滤函数 |
|
||||
| `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 绑定) |
|
||||
|
||||
事件:
|
||||
|
||||
| 事件 | 载荷 | 描述 |
|
||||
| -------------------- | ----------------------------------- | ------------- |
|
||||
| `update:modelValue` | `string \| number \| Array \| null` | 值变化 |
|
||||
| `change` | 同上 | 值变化 |
|
||||
| `update:selectedKey` | `string \| number \| null` | 单选 key 变化 |
|
||||
| `selectionChange` | `string \| number \| null` | 单选 key 变化 |
|
||||
| `update:inputValue` | `string` | 输入值变化 |
|
||||
| `inputChange` | `string` | 输入值变化 |
|
||||
| `update:open` | `boolean` | 弹层开关变化 |
|
||||
| `openChange` | `boolean` | 弹层开关变化 |
|
||||
| 事件 | 载荷 | 描述 |
|
||||
| -------------------- | ----------------------------------------------------- | ----------------------------------- |
|
||||
| `update:modelValue` | `string \| number \| Array<string \| number> \| null` | 值变化(多选时为数组) |
|
||||
| `change` | 同上 | 值变化 |
|
||||
| `update:selectedKey` | `string \| number \| null` | 单选 key 变化 |
|
||||
| `selectionChange` | `string \| number \| null` | 单选 key 变化;多选时只携带首个 key |
|
||||
| `update:inputValue` | `string` | 输入值变化 |
|
||||
| `inputChange` | `string` | 输入值变化 |
|
||||
| `update:open` | `boolean` | 弹层开关变化 |
|
||||
| `openChange` | `boolean` | 弹层开关变化 |
|
||||
|
||||
`aria-label`、`aria-labelledby`、`aria-describedby` 落在真正的 `role="combobox"` 输入框上,而不是根容器。
|
||||
|
||||
### 作用域插槽与渲染状态
|
||||
|
||||
默认插槽提供 `{ isOpen, inputValue, selectedKey, selectedKeys }`。上游的 `Render Props` 表格里还有 `state` 与 `selectedItem`:本库不暴露 React Aria 的 state 对象,选中项数据可从 `records`/`selectedKeys` 派生(示例见 `@update:model-value` 与 `ComboBoxValue` 的作用域插槽),该差异不另设等价 prop。
|
||||
|
||||
### ComboBoxInputGroup
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
@@ -337,7 +346,7 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------- | ---------------------------------- | -------------------- | ----------------------------- |
|
||||
| `placeholder` | `string` | 根上的 `placeholder` | 未选中任何项时的占位文本 |
|
||||
| `placeholder` | `string`(上游为 `ReactNode`) | 根上的 `placeholder` | 未选中任何项时的占位文本 |
|
||||
| 默认插槽 | `{ isPlaceholder, selectedItems }` | - | 自定义已选值展示 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
@@ -353,15 +362,15 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he
|
||||
|
||||
### ComboBoxPopover
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------- | --------------------------- | ---------- | ----------------------------- |
|
||||
| `placement` | 位置联合类型 | `'bottom'` | 相对触发容器的位置 |
|
||||
| `offset` | `number` | `8` | 偏移量 |
|
||||
| `should-flip` | `boolean` | `true` | 空间不足时是否翻转 |
|
||||
| `container-padding` | `number` | `12` | 距离视口边缘的最小间距 |
|
||||
| `to` | `string \| HTMLElement` | - | 自定义 Portal 容器 |
|
||||
| 默认插槽 | `Component` | - | 弹层内容(通常为 `ListBox`) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- | ----------------------------- |
|
||||
| `placement` | `'bottom' \| 'bottom left' \| 'bottom right' \| 'bottom start' \| 'bottom end' \| 'top' \| 'top left' \| 'top right' \| 'top start' \| 'top end' \| 'left' \| 'left top' \| 'left bottom' \| 'start' \| 'start top' \| 'start bottom' \| 'right' \| 'right top' \| 'right bottom' \| 'end' \| 'end top' \| 'end bottom'` | `'bottom'` | 相对触发容器的位置 |
|
||||
| `offset` | `number` | `8` | 偏移量 |
|
||||
| `should-flip` | `boolean` | `true` | 空间不足时是否翻转 |
|
||||
| `container-padding` | `number` | `12` | 距离视口边缘的最小间距 |
|
||||
| `to` | `string \| HTMLElement` | - | 自定义 Portal 容器 |
|
||||
| 默认插槽 | `Component` | - | 弹层内容(通常为 `ListBox`) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
## 无障碍
|
||||
|
||||
@@ -372,7 +381,9 @@ ComboBox 实现 ARIA combobox 模式:
|
||||
- 中文输入法组合期间不确认选择(`isComposing` / `keyCode 229` 时忽略键盘提交)
|
||||
- 过滤不会清除已接受的选择;被过滤掉的已选项仍保留标签
|
||||
- 弹层内不出现第二个 Tab 入口,关闭后移除 `aria-activedescendant`
|
||||
- 支持禁用状态(`is-disabled` / `disabled-keys`)、输入过滤式搜索、与原生表单集成(`name` / `form` / `form-value`)与自定义值(`allows-custom-value`)
|
||||
- 未实测读屏软件的变更播报与逐项读屏行为,因此不声称已通过该层验收
|
||||
|
||||
## 相关组件
|
||||
|
||||
[ListBox 列表框](./list-box) · [Select 选择器](./select) · [FieldError 字段错误](./field-error) · [Label 标签](./label)
|
||||
[ListBox 列表框](./list-box) · [Popover 弹出框](./popover) · [Input 输入框](./input)
|
||||
|
||||
Reference in New Issue
Block a user