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:
@@ -118,7 +118,10 @@ import {
|
||||
|
||||
### 变体
|
||||
|
||||
Autocomplete 支持两种视觉变体:`primary`(默认,带阴影)与 `secondary`(低强调、无阴影,适用于 Surface 内)。
|
||||
Autocomplete 组件支持两种视觉变体:
|
||||
|
||||
- **`primary`**(默认)- 标准样式带阴影,适用于大多数场景
|
||||
- **`secondary`** - 低强调变体无阴影,适用于 Surface 组件内
|
||||
|
||||
<ComponentPreview name="autocomplete-variants" />
|
||||
|
||||
@@ -144,7 +147,7 @@ Autocomplete 支持两种视觉变体:`primary`(默认,带阴影)与 `se
|
||||
|
||||
### 允许空选项
|
||||
|
||||
`allows-empty-collection` 允许集合为空时仍可打开并交互。
|
||||
`allows-empty-collection` 属性允许集合为空时仍可使用自动完成,适用于列表初始为空或全部被过滤掉的场景。
|
||||
|
||||
<ComponentPreview name="autocomplete-allows-empty-collection" />
|
||||
|
||||
@@ -156,7 +159,13 @@ Autocomplete 支持两种视觉变体:`primary`(默认,带阴影)与 `se
|
||||
|
||||
<ComponentPreview name="autocomplete-multiple-select" />
|
||||
|
||||
上游提醒:多选时 `Autocomplete.Value` 默认会把每个选中项在 `ListBox.Item` 中的子树复制到触发器里。本库不复制子树,而是给 `AutocompleteValue` 的作用域插槽提供 `selectedItems`(`{ key, textValue }[]`)与 `selectedText`(纯文本),由调用方决定渲染纯文本还是标签:
|
||||
::: warning
|
||||
多选模式下,上游 `Autocomplete.Value` 会把每个选中项在 `ListBox.Item` 中的 children 复制到触发器中,并以符合当前语言环境的分隔符连接:仅包含文本的选项显示为纯文本,但复选框、头像等可见内容会随每个选中项各出现一次;函数形式的 children 也始终以 `isSelected: false` 调用。
|
||||
|
||||
本库不复制子树,而是给 `AutocompleteValue` 的作用域插槽提供 `selectedItems`(`{ key, textValue }[]`)与 `selectedText`(纯文本),因此不存在上述重复渲染问题,但函数形式的插槽同样不携带 `isSelected`。
|
||||
:::
|
||||
|
||||
如需以纯文本显示选中值,请使用 `selectedText`:
|
||||
|
||||
```vue
|
||||
<AutocompleteValue>
|
||||
@@ -166,7 +175,7 @@ Autocomplete 支持两种视觉变体:`primary`(默认,带阴影)与 `se
|
||||
</AutocompleteValue>
|
||||
```
|
||||
|
||||
需要可移除标签时用 `selectedItems` 自行渲染,示例见「多选」。
|
||||
如需可移除标签等更丰富的布局,可基于 `selectedItems` 自行渲染内容,示例见「高级示例 / 标签组选择」。
|
||||
|
||||
### 受控组件
|
||||
|
||||
@@ -196,7 +205,7 @@ Autocomplete 支持两种视觉变体:`primary`(默认,带阴影)与 `se
|
||||
|
||||
### 表面样式
|
||||
|
||||
在 Surface 内使用时请用 `variant="secondary"`。
|
||||
在 [Surface](/components/surface) 组件内使用时,请使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体。
|
||||
|
||||
<ComponentPreview name="autocomplete-on-surface" />
|
||||
|
||||
@@ -237,6 +246,7 @@ Autocomplete 支持两种视觉变体:`primary`(默认,带阴影)与 `se
|
||||
### 全局 CSS
|
||||
|
||||
可使用 `@layer components` 指令自定义 Autocomplete 组件类。
|
||||
[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
@@ -277,7 +287,7 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co
|
||||
#### 基础类
|
||||
|
||||
- `.hv-autocomplete` - 根容器
|
||||
- `.hv-autocomplete__trigger` - 展示值并打开弹层的容器
|
||||
- `.hv-autocomplete__trigger` - 触发自动完成的按钮(本库渲染为 `role="button"` 的容器)
|
||||
- `.hv-autocomplete__value` - 值或占位符
|
||||
- `.hv-autocomplete__clear-button` - 清除已选值的按钮
|
||||
- `.hv-autocomplete__indicator` - 下拉指示图标
|
||||
@@ -287,15 +297,13 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co
|
||||
#### 变体类
|
||||
|
||||
- `.hv-autocomplete--primary` - 带阴影的主变体(默认)
|
||||
- `.hv-autocomplete--secondary` - 无阴影的次变体
|
||||
- `.hv-autocomplete--secondary` - 无阴影的次变体,适用于 Surface 内
|
||||
|
||||
#### 状态类
|
||||
|
||||
- `.hv-autocomplete[data-invalid="true"]` - 无效状态
|
||||
- `.hv-autocomplete[data-disabled="true"]` - 禁用状态
|
||||
- `.hv-autocomplete__trigger[data-focus-visible="true"]` - 触发器聚焦
|
||||
- `.hv-autocomplete__trigger[data-disabled="true"]` - 触发器禁用
|
||||
- `.hv-autocomplete__trigger[data-open="true"]` - 展开状态
|
||||
- `.hv-autocomplete__value[data-placeholder="true"]` - 占位符状态
|
||||
- `.hv-autocomplete__clear-button[data-empty="true"]` - 无选择时隐藏清除按钮
|
||||
- `.hv-autocomplete__indicator[data-open="true"]` - 打开时图标旋转 180°
|
||||
@@ -303,45 +311,48 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co
|
||||
### 交互状态
|
||||
|
||||
- **Hover**:触发器上 `:hover` 或 `[data-hovered="true"]`
|
||||
- **Focus**:触发器与搜索框上 `:focus-visible`
|
||||
- **Disabled**:根与触发器上 `[data-disabled="true"]`
|
||||
- **Open**:触发器上 `[data-open="true"]`、指示器上 `[data-open="true"]`
|
||||
- **Focus**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **Disabled**:触发器上 `[data-disabled="true"]`
|
||||
- **Open**:指示器上 `[data-open="true"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
### 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 \| null` | - | 当前值(受控,`v-model`) |
|
||||
| `value` | `string \| number \| Array \| null` | - | 同 `model-value`(受控别名) |
|
||||
| `default-value` | `string \| number \| Array \| null` | - | 初始值(非受控) |
|
||||
| `is-required` | `boolean` | `false` | 是否必填 |
|
||||
| `is-invalid` | `boolean` | `false` | 值是否无效 |
|
||||
| `name` | `string` | - | 表单提交字段名(输出隐藏输入,多选以逗号连接) |
|
||||
| `form` | `string` | - | 关联的表单 id |
|
||||
| `full-width` | `boolean` | `false` | 是否占满容器宽度 |
|
||||
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体 |
|
||||
| `as` | `string` | `'div'` | 自定义根元素标签 |
|
||||
| `as-child` | `boolean` | `false` | 使用唯一子元素作为根节点并合并属性 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
| 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 绑定) |
|
||||
|
||||
事件:
|
||||
|
||||
| 事件 | 载荷 | 描述 |
|
||||
| ------------------- | ----------------------------------- | ------------ |
|
||||
| `update:modelValue` | `string \| number \| Array \| null` | 值变化 |
|
||||
| `change` | 同上 | 值变化 |
|
||||
| `update:open` | `boolean` | 弹层开关变化 |
|
||||
| `openChange` | `boolean` | 弹层开关变化 |
|
||||
| `clear` | - | 清除已选值 |
|
||||
| 事件 | 载荷 | 描述 |
|
||||
| ------------------- | ----------------------------------------------------- | ---------------------- |
|
||||
| `update:modelValue` | `string \| number \| Array<string \| number> \| null` | 值变化(多选时为数组) |
|
||||
| `change` | 同上 | 值变化 |
|
||||
| `update:open` | `boolean` | 弹层开关变化 |
|
||||
| `openChange` | `boolean` | 弹层开关变化 |
|
||||
| `clear` | - | 清除已选值 |
|
||||
|
||||
### AutocompleteTrigger
|
||||
|
||||
@@ -378,17 +389,19 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co
|
||||
|
||||
`aria-label` 默认 `Clear selection`,`tabindex="-1"`,无选择时 `data-empty="true"` 并隐藏。
|
||||
|
||||
`@click` 与内部清除处理会合并执行(Vue 事件数组);模板 ref 通过 `defineExpose` 暴露组件实例,需要 DOM 时取 `$el`。
|
||||
|
||||
### AutocompletePopover
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------- | --------------------------- | ---------- | ----------------------------- |
|
||||
| `placement` | 位置联合类型 | `'bottom'` | 相对触发器的位置 |
|
||||
| `offset` | `number` | `8` | 偏移量 |
|
||||
| `should-flip` | `boolean` | `true` | 空间不足时是否翻转 |
|
||||
| `container-padding` | `number` | `12` | 距离视口边缘的最小间距 |
|
||||
| `to` | `string \| HTMLElement` | - | 自定义 Portal 容器 |
|
||||
| 默认插槽 | `Component` | - | 通常为 `AutocompleteFilter` |
|
||||
| `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` | - | 通常为 `AutocompleteFilter` |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
宽度跟随触发器(`--trigger-width`)。
|
||||
|
||||
@@ -415,15 +428,23 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co
|
||||
|
||||
`AutocompleteValue` 的默认插槽提供:
|
||||
|
||||
| 字段 | 类型 | 描述 |
|
||||
| ----------------- | --------------------------- | -------------------------------------------- |
|
||||
| `isPlaceholder` | `boolean` | 是否没有选中项 |
|
||||
| `defaultChildren` | `string` | 缺省文本(选中项文本以逗号连接,否则占位符) |
|
||||
| `selectedText` | `string` | 选中项 `textValue` 的连接文本 |
|
||||
| `selectedItems` | `Array<{ key, textValue }>` | 选中项 |
|
||||
| 字段 | 类型 | 描述 |
|
||||
| ----------------- | ------------------------------ | -------------------------------------------- |
|
||||
| `isPlaceholder` | `boolean` | 是否没有选中项 |
|
||||
| `defaultChildren` | `string`(上游为 `ReactNode`) | 缺省文本(选中项文本以逗号连接,否则占位符) |
|
||||
| `selectedText` | `string` | 选中项 `textValue` 的连接文本 |
|
||||
| `selectedItems` | `Array<{ key, textValue }>` | 选中项 |
|
||||
|
||||
上游 `state.selectedItems`(节点)在本库中是上表的 `selectedItems`(数据);不复制 item 子树,见「多选」说明。
|
||||
|
||||
### 过滤函数(`useFilter` 替代)
|
||||
|
||||
上游页面导出的 `useFilter` hook(`contains` / `startsWith` / `endsWith` 与 `sensitivity`)在本库没有对应导出。替代方式:
|
||||
|
||||
- `AutocompleteFilter` 的默认谓词等价于 `useFilter({ sensitivity: "base" }).contains`(不区分大小写的包含匹配)
|
||||
- 需要 `startsWith` / `endsWith` 等语义时,直接给 `:filter="(text, input) => …"` 传函数
|
||||
- 数据源或调用方已过滤时(异步、虚拟化示例),传 `:filter="() => true"` 避免二次过滤
|
||||
|
||||
## 无障碍
|
||||
|
||||
Autocomplete 实现带过滤的 ARIA select 模式:
|
||||
@@ -433,7 +454,9 @@ Autocomplete 实现带过滤的 ARIA select 模式:
|
||||
- `ArrowDown` / `ArrowUp` / `Home` / `End` 在过滤后的可见集合中移动,`Enter` 确认,`Escape` 关闭,`Tab` 离开
|
||||
- 中文输入法组合期间不确认选择(`isComposing` / `keyCode 229` 时忽略键盘提交)
|
||||
- 过滤不会清除已接受的选择;关闭后焦点回到触发器,弹层内不出现第二个 Tab 入口
|
||||
- 支持禁用状态(`is-disabled` / `disabled-keys`)、带过滤的搜索、与原生表单集成(`name` / `form`)
|
||||
- 未实测读屏软件的变更播报与逐项读屏行为,因此不声称已通过该层验收
|
||||
|
||||
## 相关组件
|
||||
|
||||
[ComboBox 组合框](./combo-box) · [Select 选择器](./select) · [ListBox 列表框](./list-box) · [SearchField 搜索框](./search-field)
|
||||
[ListBox 列表框](./list-box) · [Popover 弹出框](./popover) · [Input 输入框](./input)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Label,
|
||||
ListBox,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -32,15 +33,21 @@ import {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -29,19 +29,20 @@ type Character = {
|
||||
|
||||
const SEARCH_DELAY = 300;
|
||||
|
||||
// SWAPI 返回的角色名(源示例直接用 item.name 作为 id 与文本)。
|
||||
const characters: Character[] = [
|
||||
{ id: "luke-skywalker", name: "卢克·天行者" },
|
||||
{ id: "princess-leia", name: "莱娅公主" },
|
||||
{ id: "han-solo", name: "汉·索罗" },
|
||||
{ id: "darth-vader", name: "达斯·维达" },
|
||||
{ id: "yoda", name: "尤达" },
|
||||
{ id: "obi-wan-kenobi", name: "欧比旺·克诺比" },
|
||||
{ id: "palpatine", name: "帕尔帕廷" },
|
||||
{ id: "lando-calrissian", name: "兰多·卡瑞辛" },
|
||||
{ id: "chewbacca", name: "楚巴卡" },
|
||||
{ id: "r2-d2", name: "R2-D2" },
|
||||
{ id: "c-3po", name: "C-3PO" },
|
||||
{ id: "boba-fett", name: "波巴·费特" },
|
||||
{ id: "Luke Skywalker", name: "Luke Skywalker" },
|
||||
{ id: "Princess Leia", name: "Princess Leia" },
|
||||
{ id: "Han Solo", name: "Han Solo" },
|
||||
{ id: "Darth Vader", name: "Darth Vader" },
|
||||
{ id: "Yoda", name: "Yoda" },
|
||||
{ id: "Obi-Wan Kenobi", name: "Obi-Wan Kenobi" },
|
||||
{ id: "Palpatine", name: "Palpatine" },
|
||||
{ id: "Lando Calrissian", name: "Lando Calrissian" },
|
||||
{ id: "Chewbacca", name: "Chewbacca" },
|
||||
{ id: "R2-D2", name: "R2-D2" },
|
||||
{ id: "C-3PO", name: "C-3PO" },
|
||||
{ id: "Boba Fett", name: "Boba Fett" },
|
||||
];
|
||||
|
||||
const query = ref("");
|
||||
@@ -144,7 +145,7 @@ const keepResults = () => true;
|
||||
</ListBoxItem>
|
||||
</template>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -48,10 +49,16 @@ const selected = ref<TagKey[]>(["california", "texas"]);
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -65,7 +72,7 @@ const selected = ref<TagKey[]>(["california", "texas"]);
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -49,10 +50,16 @@ const isOpen = ref(false);
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -66,7 +73,7 @@ const isOpen = ref(false);
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -51,10 +52,16 @@ const selectedState = computed(() =>
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -68,7 +75,7 @@ const selectedState = computed(() =>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -43,16 +44,22 @@ const selectedKey = ref<string | null>(null);
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator>
|
||||
<IconSelector class="size-3" aria-hidden="true" />
|
||||
<AutocompleteIndicator class="size-3">
|
||||
<IconSelector aria-hidden="true" />
|
||||
</AutocompleteIndicator>
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -66,7 +73,7 @@ const selectedKey = ref<string | null>(null);
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -116,7 +116,7 @@ function onRemoveTags(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到团队成员</EmptyState>
|
||||
<EmptyState>未找到团队成员</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -89,7 +89,7 @@ const currencyOf = (key: unknown) =>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
@@ -14,6 +13,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -71,10 +71,16 @@ function onRemoveTags(keys: TagKey[]) {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索选项"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -88,7 +94,7 @@ function onRemoveTags(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -54,10 +55,16 @@ const countries = [
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -71,7 +78,7 @@ const countries = [
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
@@ -92,10 +99,16 @@ const countries = [
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索国家">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索国家"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索国家…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -109,7 +122,7 @@ const countries = [
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -107,7 +107,7 @@ function onRemoveTags(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到收件人</EmptyState>
|
||||
<EmptyState>未找到收件人</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -49,10 +50,16 @@ const selectedKey = ref<string | null>(null);
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -66,7 +73,7 @@ const selectedKey = ref<string | null>(null);
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -103,7 +103,7 @@ onBeforeUnmount(() => clearTimeout(timer));
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">
|
||||
<EmptyState>
|
||||
{{ loading ? "搜索中…" : "未找到城市" }}
|
||||
</EmptyState>
|
||||
</template>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -72,10 +73,16 @@ function onRemoveTags(keys: TagKey[]) {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索选项"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -89,7 +96,7 @@ function onRemoveTags(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -73,7 +73,7 @@ const selectedKey = ref<string | null>(null);
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -45,7 +46,8 @@ const message = ref<string | null>(null);
|
||||
function onSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(event.currentTarget as HTMLFormElement);
|
||||
message.value = `表单提交成功!州:${formData.get("state")},国家:${formData.get("country")}`;
|
||||
void formData;
|
||||
message.value = "表单提交成功!";
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -66,10 +68,16 @@ function onSubmit(event: Event) {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -83,7 +91,7 @@ function onSubmit(event: Event) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
@@ -105,10 +113,16 @@ function onSubmit(event: Event) {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索国家">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索国家"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索国家…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -122,7 +136,7 @@ function onSubmit(event: Event) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
@@ -130,7 +144,7 @@ function onSubmit(event: Event) {
|
||||
<FieldError />
|
||||
</Autocomplete>
|
||||
<Button type="submit">提交</Button>
|
||||
<p v-if="message" role="status" class="text-sm text-success">
|
||||
<p v-if="message" role="status" class="text-sm text-muted">
|
||||
{{ message }}
|
||||
</p>
|
||||
</Form>
|
||||
|
||||
@@ -98,7 +98,7 @@ function onRemoveTags(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到标签</EmptyState>
|
||||
<EmptyState>未找到标签</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -149,7 +149,7 @@ function onRemoveTags(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -137,7 +137,7 @@ const userOf = (key: unknown) => users.find((user) => user.id === key);
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -68,10 +69,16 @@ function onRemoveTags2(keys: TagKey[]) {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索选项"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -85,7 +92,7 @@ function onRemoveTags2(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
@@ -106,10 +113,16 @@ function onRemoveTags2(keys: TagKey[]) {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索选项"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -123,7 +136,7 @@ function onRemoveTags2(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
@@ -169,10 +182,16 @@ function onRemoveTags2(keys: TagKey[]) {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索选项"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -186,7 +205,7 @@ function onRemoveTags2(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
@@ -232,10 +251,16 @@ function onRemoveTags2(keys: TagKey[]) {
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索选项"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -249,7 +274,7 @@ function onRemoveTags2(keys: TagKey[]) {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -166,7 +166,7 @@ const keepResults = () => true;
|
||||
</ListBoxItem>
|
||||
</template>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -47,10 +48,16 @@ const selectedKey = ref<string | null>(null);
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索州名"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -64,7 +71,7 @@ const selectedKey = ref<string | null>(null);
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -47,10 +48,16 @@ const selectedKey = ref<string | null>(null);
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索动物">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索动物"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索动物…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -64,7 +71,7 @@ const selectedKey = ref<string | null>(null);
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
ListBoxItemIndicator,
|
||||
ListBoxSection,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
@@ -40,10 +41,16 @@ const selectedKey = ref<string | null>(null);
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索国家">
|
||||
<SearchField
|
||||
auto-focus
|
||||
name="search"
|
||||
variant="secondary"
|
||||
aria-label="搜索国家"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索国家…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
@@ -107,7 +114,7 @@ const selectedKey = ref<string | null>(null);
|
||||
</ListBoxItem>
|
||||
</ListBoxSection>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
<EmptyState>未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
|
||||
@@ -25,18 +25,18 @@ const PAGE_SIZE = 4;
|
||||
const PAGE_DELAY = 300;
|
||||
|
||||
const characters: Character[] = [
|
||||
{ id: "luke-skywalker", name: "卢克·天行者" },
|
||||
{ id: "princess-leia", name: "莱娅公主" },
|
||||
{ id: "han-solo", name: "汉·索罗" },
|
||||
{ id: "darth-vader", name: "达斯·维达" },
|
||||
{ id: "yoda", name: "尤达" },
|
||||
{ id: "obi-wan-kenobi", name: "欧比旺·克诺比" },
|
||||
{ id: "palpatine", name: "帕尔帕廷" },
|
||||
{ id: "lando-calrissian", name: "兰多·卡瑞辛" },
|
||||
{ id: "chewbacca", name: "楚巴卡" },
|
||||
{ id: "r2-d2", name: "R2-D2" },
|
||||
{ id: "c-3po", name: "C-3PO" },
|
||||
{ id: "boba-fett", name: "波巴·费特" },
|
||||
{ id: "Luke Skywalker", name: "Luke Skywalker" },
|
||||
{ id: "Princess Leia", name: "Princess Leia" },
|
||||
{ id: "Han Solo", name: "Han Solo" },
|
||||
{ id: "Darth Vader", name: "Darth Vader" },
|
||||
{ id: "Yoda", name: "Yoda" },
|
||||
{ id: "Obi-Wan Kenobi", name: "Obi-Wan Kenobi" },
|
||||
{ id: "Palpatine", name: "Palpatine" },
|
||||
{ id: "Lando Calrissian", name: "Lando Calrissian" },
|
||||
{ id: "Chewbacca", name: "Chewbacca" },
|
||||
{ id: "R2-D2", name: "R2-D2" },
|
||||
{ id: "C-3PO", name: "C-3PO" },
|
||||
{ id: "Boba Fett", name: "Boba Fett" },
|
||||
];
|
||||
|
||||
const inputValue = ref("");
|
||||
@@ -139,9 +139,7 @@ onBeforeUnmount(() => {
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">
|
||||
{{ loading ? "正在加载…" : "没有找到角色" }}
|
||||
</EmptyState>
|
||||
<EmptyState />
|
||||
</template>
|
||||
</ListBox>
|
||||
<div v-if="hasMore" class="flex items-center justify-center gap-2 py-2">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
ComboBox,
|
||||
@@ -35,8 +36,10 @@ function validate(value: string | number | (string | number)[] | null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const message = ref("");
|
||||
|
||||
function onSubmit() {
|
||||
alert("表单提交成功!");
|
||||
message.value = "表单提交成功!";
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -64,5 +67,6 @@ function onSubmit() {
|
||||
<FieldError />
|
||||
</ComboBox>
|
||||
<Button class="w-fit" type="submit">提交</Button>
|
||||
<p v-if="message" class="text-sm text-muted" role="status">{{ message }}</p>
|
||||
</Form>
|
||||
</template>
|
||||
|
||||
@@ -81,6 +81,6 @@ function onSubmit(event: Event) {
|
||||
<FieldError />
|
||||
</ComboBox>
|
||||
<Button class="w-fit" type="submit">提交</Button>
|
||||
<p v-if="message" class="text-sm text-muted">{{ message }}</p>
|
||||
<p v-if="message" class="text-sm text-muted" role="status">{{ message }}</p>
|
||||
</Form>
|
||||
</template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
ComboBox,
|
||||
@@ -15,9 +16,11 @@ import {
|
||||
Surface,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const message = ref("");
|
||||
|
||||
function onSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
alert("表单提交成功!");
|
||||
message.value = "表单提交成功!";
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -61,6 +64,9 @@ function onSubmit(event: Event) {
|
||||
<FieldError />
|
||||
</ComboBox>
|
||||
<Button type="submit">提交</Button>
|
||||
<p v-if="message" class="text-sm text-muted" role="status">
|
||||
{{ message }}
|
||||
</p>
|
||||
</Form>
|
||||
</Surface>
|
||||
</template>
|
||||
|
||||
@@ -18,14 +18,9 @@ import {
|
||||
const submitted = ref(false);
|
||||
|
||||
function submit(event: Event) {
|
||||
const formData = new FormData(event.currentTarget as HTMLFormElement);
|
||||
const data: Record<string, string> = {};
|
||||
|
||||
formData.forEach((value, key) => {
|
||||
data[key] = value.toString();
|
||||
});
|
||||
|
||||
submitted.value = "animal" in data;
|
||||
// The Form guard already blocks invalid submits, so a reached handler is valid.
|
||||
void new FormData(event.currentTarget as HTMLFormElement);
|
||||
submitted.value = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -68,7 +63,7 @@ function submit(event: Event) {
|
||||
<FieldError />
|
||||
</ComboBox>
|
||||
<Button type="submit">提交</Button>
|
||||
<p v-if="submitted" role="status" class="text-sm text-success">
|
||||
<p v-if="submitted" role="status" class="text-sm text-muted">
|
||||
表单提交成功!
|
||||
</p>
|
||||
</Form>
|
||||
|
||||
@@ -70,7 +70,9 @@ function submitAria(event: Event) {
|
||||
<FieldError />
|
||||
</ComboBox>
|
||||
<Button class="w-fit" type="submit">提交</Button>
|
||||
<p v-if="nativeMessage" class="text-sm text-muted">{{ nativeMessage }}</p>
|
||||
<p v-if="nativeMessage" class="text-sm text-muted" role="status">
|
||||
{{ nativeMessage }}
|
||||
</p>
|
||||
</Form>
|
||||
<Form class="flex w-[256px] flex-col gap-4" @submit="submitAria">
|
||||
<ComboBox
|
||||
@@ -101,7 +103,9 @@ function submitAria(event: Event) {
|
||||
<FieldError />
|
||||
</ComboBox>
|
||||
<Button class="w-fit" type="submit">提交</Button>
|
||||
<p v-if="ariaMessage" class="text-sm text-muted">{{ ariaMessage }}</p>
|
||||
<p v-if="ariaMessage" class="text-sm text-muted" role="status">
|
||||
{{ ariaMessage }}
|
||||
</p>
|
||||
</Form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -350,3 +350,113 @@ export interface CollectionOwner extends CollectionView {
|
||||
- 真实系统 IME、读屏软件、逐像素视觉对比。
|
||||
- 弹层内浮层选项的真实鼠标点击(本 IAB 对 floating option 报 `not actionable`;键盘与 DOM 断言覆盖,指针保焦点由 B02a harness 覆盖)。
|
||||
- 完整独立产物类型正反例矩阵(bundler / NodeNext 的公开类型契约)留在 B02d。
|
||||
|
||||
## 13. 逐示例对照复核(48 例)
|
||||
|
||||
### 13.1 方法与范围
|
||||
|
||||
按用户要求把 48 个已迁移示例逐例与固定基线核对,基准是提交 `ce90ea3` 的 `apps/docs/src/demos/cn/combo-box/*.tsx`、`apps/docs/src/demos/cn/autocomplete/*.tsx` 与 `apps/docs/content/docs/cn/react/components/(pickers)/` 下两页中文文档。
|
||||
|
||||
复核分五路并行:ComboBox 示例 1–12、ComboBox 示例 13–24、ComboBox 与 Autocomplete 文档、Autocomplete 示例 1–12、Autocomplete 示例 13–24。每路核对控件数量与嵌套、文案字节、类名集合、属性名与默认值,以及可操作行为(键盘、过滤、表单值、受控拒绝)。
|
||||
|
||||
复核后另用一次性脚本(未提交)把每个上游 `.tsx` 与本仓库 `apps/docs/demos/<component>-<name>.vue` 的中文字面量与 JSX 文本集合、`className` / `class` 字符串集合做双向包含比较,作为下表"文案"与"类名"两列的机械证据;结构与行为差异仍由人工判断,不能只看集合相等。
|
||||
|
||||
### 13.2 ComboBox 24 例
|
||||
|
||||
| 示例 | 文案 | 类名 | 结论 |
|
||||
| ------------------------ | ---- | ------ | ------------------------------------------------------------------ |
|
||||
| `allows-custom-value` | 一致 | 一致 | 一致 |
|
||||
| `asynchronous-loading` | 一致 | 有差异 | 差异已记录:`muted text-sm` → `text-sm text-muted`(同组类名顺序) |
|
||||
| `controlled-input-value` | 一致 | 一致 | 一致 |
|
||||
| `controlled` | 一致 | 一致 | 一致 |
|
||||
| `custom-filtering` | 一致 | 一致 | 一致 |
|
||||
| `custom-indicator` | 一致 | 一致 | 一致 |
|
||||
| `custom-styles` | 一致 | 有差异 | 差异已记录:item 类抽为 `itemClass` 常量(值相同) |
|
||||
| `custom-validation` | 一致 | 有差异 | 差异已记录:`alert()` → 页内 `role="status"`(约定差异) |
|
||||
| `custom-value` | 一致 | 一致 | 一致 |
|
||||
| `default-selected-key` | 一致 | 一致 | 一致 |
|
||||
| `default` | 一致 | 一致 | 一致 |
|
||||
| `disabled` | 一致 | 一致 | 一致 |
|
||||
| `form-value` | 一致 | 一致 | 一致 |
|
||||
| `full-width` | 一致 | 一致 | 一致 |
|
||||
| `menu-trigger` | 一致 | 一致 | 一致 |
|
||||
| `multiple-selection` | 一致 | 一致 | 一致 |
|
||||
| `on-surface` | 一致 | 有差异 | 差异已记录:`alert()` → 页内 `role="status"`(约定差异) |
|
||||
| `read-only` | 一致 | 一致 | 一致 |
|
||||
| `render-function` | 一致 | 一致 | 一致 |
|
||||
| `required` | 一致 | 有差异 | 差异已记录:`alert()` → 页内 `role="status"`(约定差异) |
|
||||
| `validation-behavior` | 一致 | 一致 | 一致 |
|
||||
| `with-description` | 一致 | 一致 | 一致 |
|
||||
| `with-disabled-options` | 一致 | 一致 | 一致 |
|
||||
| `with-sections` | 一致 | 一致 | 一致 |
|
||||
|
||||
### 13.3 Autocomplete 24 例
|
||||
|
||||
| 示例 | 文案 | 类名 | 结论 |
|
||||
| ------------------------- | ------ | ------ | ------------------------------------------------------------------------------------------------ |
|
||||
| `allows-empty-collection` | 一致 | 一致 | 一致 |
|
||||
| `asynchronous-filtering` | 一致 | 有差异 | 差异已记录:加载态类用对象绑定表达上游 `cn(...)` 的三元结果(值相同) |
|
||||
| `controlled-multiple` | 一致 | 一致 | 一致 |
|
||||
| `controlled-open-state` | 一致 | 一致 | 一致 |
|
||||
| `controlled` | 一致 | 一致 | 一致 |
|
||||
| `custom-indicator` | 一致 | 一致 | 一致 |
|
||||
| `custom-styles` | 一致 | 一致 | 一致 |
|
||||
| `custom-value` | 一致 | 一致 | 一致 |
|
||||
| `default` | 一致 | 一致 | 一致 |
|
||||
| `disabled` | 一致 | 一致 | 一致 |
|
||||
| `email-recipients` | 一致 | 一致 | 一致 |
|
||||
| `full-width` | 一致 | 一致 | 一致 |
|
||||
| `location-search` | 一致 | 一致 | 一致 |
|
||||
| `multiple-select` | 一致 | 一致 | 一致 |
|
||||
| `on-surface` | 一致 | 一致 | 一致 |
|
||||
| `required` | 一致 | 有差异 | 差异已记录:`alert()` → 页内 `role="status"`(约定差异) |
|
||||
| `tag-group-selection` | 一致 | 一致 | 一致 |
|
||||
| `user-selection-multiple` | 一致 | 一致 | 一致 |
|
||||
| `user-selection` | 有差异 | 一致 | 差异已记录:上游单选模式下不可达的 `已选择 N 位用户` 分支未复刻 |
|
||||
| `variants` | 一致 | 一致 | 一致 |
|
||||
| `virtualization` | 一致 | 有差异 | 差异已记录:多出 `max-h-[320px] overflow-y-auto`(弹层 CSS 已含)与行 `h-full`(无 Virtualizer) |
|
||||
| `with-description` | 一致 | 一致 | 一致 |
|
||||
| `with-disabled-options` | 一致 | 一致 | 一致 |
|
||||
| `with-sections` | 一致 | 一致 | 一致 |
|
||||
|
||||
### 13.4 本轮修掉的真实偏差
|
||||
|
||||
1. **CSS `data-slot` 值被批量加前缀**:见 13.5,是本轮最严重的问题——选择器全部落空,触发器图标不旋转、指示器与清除图标尺寸失效。
|
||||
2. **`allowsCustomValue` 此前只是展示行为**:输入不匹配文本后回车不做任何事。现在 `ComboBox.confirmActive` 在无匹配项且允许自定义值时把键入文本提交为值并关闭,与上游一致。
|
||||
3. `combo-box-on-surface`、`combo-box-custom-validation` 使用 `alert()`,与项目既有约定不符 → 改为页内 `role="status"` 段落。
|
||||
4. `combo-box-form-value`、`combo-box-validation-behavior`(两处反馈)缺 `role="status"` → 补齐。
|
||||
5. `combo-box-required` 的成功文案用 `text-success`,上游无此配色 → `text-muted`;同时提交处理改为不再靠 `"animal" in data` 判断,因 `Form` 守卫已拦下无效提交。
|
||||
6. `combo-box-asynchronous-loading` 的空状态被加了 `p-1` 与自写文案,上游是裸 `<EmptyState />` → 还原;加载中提示由底部「加载更多…」状态承担。
|
||||
7. 24 个 Autocomplete 示例的弹层搜索框缺少上游的 `autoFocus` / `name="search"` / `variant="secondary"` / `SearchField.ClearButton` 壳层 → 全部补齐;同时去掉仓库内自加的 `EmptyState class="p-1"`(上游 `.empty-state` 是 `p-2`,弹层只补排版类)。
|
||||
8. `apps/docs/components/combo-box.md`:补 `open` / `is-open` / `default-open` 行、`placeholder` 默认值 `'Select an item'`、`Array<string | number>` 具体类型、`placement` 完整联合、Surface 与「了解更多」链接、作用域插槽与上游 `Render Props` 的等价说明;修正多选一节误推 `@selection-change` 的表述;组件结构块不再渲染上游未渲染的 `Separator`,`ListBoxItem` 补 `Label` + `Description` + `ListBoxItemIndicator`;无障碍与相关组件(ListBox · Popover · Input)按上游补齐。
|
||||
9. `apps/docs/components/autocomplete.md`:补根组件 `validate` / `validation-behavior` 与默认插槽作用域 `{ isOpen, selectedKeys }`、`AutocompleteClearButton` 的 `@click` 与模板 ref 行为、变体两条粗体、多选 `::: warning` 全文、`useFilter` 替代说明;删除没有对应 CSS 规则的状态类;修正交互状态中 Focus 与 Open 的落点。
|
||||
|
||||
### 13.5 CSS `data-slot` 前缀事故(教训)
|
||||
|
||||
移植样式时用整文件替换把 `combo-box` → `hv-combo-box`、`autocomplete` → `hv-autocomplete`,连 `[data-slot="combo-box-trigger-default-icon"]`、`[data-slot="autocomplete-default-indicator"]`、`[data-slot="autocomplete-clear-button-icon"]` 这类**属性值**也一起改了;组件输出的仍是无前缀值,于是这些规则全部落空。
|
||||
|
||||
`pnpm build:docs` 产物 `apps/docs/.vitepress/dist/assets/style.*.css` 中的修复后证据:
|
||||
|
||||
- `.hv-combo-box__trigger[data-open=true] [data-slot=combo-box-trigger-default-icon]{rotate:180deg}`,同时该图标带 `transform/rotate` 过渡与 reduced-motion 分支;
|
||||
- `.hv-autocomplete__indicator[data-slot=autocomplete-default-indicator]{width/height:1rem}`;
|
||||
- `.hv-autocomplete__clear-button [data-slot=autocomplete-clear-button-icon]{width/height:0.875rem}`;
|
||||
- 全文件 `data-slot="hv-` 计数为 0。
|
||||
|
||||
规则:`hv-` 前缀只作用于**类名**;`data-slot` 的属性值必须与 DOM 输出逐字节一致。回归放在 `tests/combo-box.test.ts` 与 `tests/autocomplete.test.ts`:断言样式源码不含 `data-slot="hv-`、目标选择器存在,并且真实 DOM 在同一父节点下带 `data-open` 与对应图标槽(旋转与尺寸因此可达)。
|
||||
|
||||
### 13.6 保留的项目约定差异(不再改)
|
||||
|
||||
1. `alert()` → 页内 `role="status"`(ComboBox 3 例、Autocomplete 1 例)。
|
||||
2. `className` → `class`;`render` / render props → `as` / `as-child` / 作用域插槽;对象式子部件 → 具名导出。
|
||||
3. 无 `useFilter` / `Virtualizer` / `renderEmptyState`:默认过滤谓词、`ListBox items + virtualized + row-height`、`#empty` 插槽分别承接。
|
||||
4. 异步示例用本地数据源(ComboBox 300ms 假延迟 + 显式「加载更多」,Autocomplete 300ms + `AbortController`),上游是 SWAPI + `useAsyncList` 分页。
|
||||
5. `user-selection` 未复刻上游在单选模式下不可达的「已选择 N 位用户」分支。
|
||||
6. `virtualization` 多写一次 `max-h-[320px] overflow-y-auto`(弹层 CSS 已含,无视觉影响)与行 `h-full`(替代 Virtualizer 的行包装)。
|
||||
7. 演示反馈段落统一 `text-sm text-muted`;因此 `alert()` 那几例的类集合与上游不同。
|
||||
8. 文档 frontmatter 用 `component` / `group`(来源链接按路由推导),不保留上游 `links:` 块;`useFilter` 一章改写为替代说明。
|
||||
|
||||
### 13.7 本轮验证
|
||||
|
||||
- `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` 变体无阴影、自定义值回车后的展示与关闭。
|
||||
|
||||
@@ -1035,3 +1035,11 @@ Tag/TagGroup/ErrorMessage 的最新验收见 [B03 复核记录](migrations/B03-r
|
||||
- 独立 tarball 消费(`/private/tmp/b02-consumer`,两族共用脚本 `tests/package/consume-b02-pickers.mjs`):导出、SSR HTML 契约、CSS 选择器与变体函数均通过;完整类型正反例矩阵留给 B02d。
|
||||
- 浏览器 5182(Chromium/IAB):29 个触发器;打开后焦点进入弹层内 `role="combobox"` 搜索框且 `aria-activedescendant` 指向真实 option;输入 “Te” 只留 Texas 且活动项随之更新;多选 `Enter` 后保持打开并显示标签;空集合示例直接显示“未找到结果”;分组示例 12 行 3 组;虚拟化示例 1000 行仅挂载 12 行,`End` 后 `scrollTop` 49692、活动项在视口内;禁用触发器 `tabindex=-1`;弹层宽度 256 = 触发器宽度;浅/深色触发器背景正确;控制台无 error/warning。
|
||||
- 未验证:真实系统 IME、读屏软件、逐像素对比、浮层选项的真实鼠标点击(本 IAB 报 `not actionable`)、完整产物类型正反例(B02d)。
|
||||
|
||||
## 2026-10-25 B02 逐示例对照复核
|
||||
|
||||
48 个示例逐例与固定基线核对的过程、逐例结论表与差异清单见 [B02 报告](migrations/B02-combobox-autocomplete.md) 第 13 节;本段只记录本轮命令与证据。
|
||||
|
||||
- `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 变体与自定义值展示。
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
@apply rotate-180;
|
||||
}
|
||||
|
||||
&[data-slot="hv-autocomplete-default-indicator"] {
|
||||
&[data-slot="autocomplete-default-indicator"] {
|
||||
@apply size-4;
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,7 @@
|
||||
@apply pointer-events-none opacity-0;
|
||||
}
|
||||
|
||||
[data-slot="hv-autocomplete-clear-button-icon"] {
|
||||
[data-slot="autocomplete-clear-button-icon"] {
|
||||
@apply size-3.5;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,12 +89,12 @@
|
||||
@apply cursor-not-allowed opacity-50;
|
||||
}
|
||||
|
||||
[data-slot="hv-combo-box-trigger-default-icon"] {
|
||||
[data-slot="combo-box-trigger-default-icon"] {
|
||||
@apply size-4 transition-transform duration-150 motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* Rotate icon when trigger is open */
|
||||
&[data-open="true"] [data-slot="hv-combo-box-trigger-default-icon"] {
|
||||
&[data-open="true"] [data-slot="combo-box-trigger-default-icon"] {
|
||||
@apply rotate-180;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,11 +373,23 @@ export default defineComponent({
|
||||
|
||||
function confirmActive() {
|
||||
const key = activeKey.value;
|
||||
if (key === undefined) return;
|
||||
const record = records.value.find(
|
||||
(item) => item.key === key && filter(item) && !item.disabled,
|
||||
);
|
||||
if (!record) return;
|
||||
const record =
|
||||
key === undefined
|
||||
? undefined
|
||||
: records.value.find(
|
||||
(item) => item.key === key && filter(item) && !item.disabled,
|
||||
);
|
||||
if (key === undefined || !record) {
|
||||
const typed = inputValue.value.trim();
|
||||
// A custom value is the typed text itself, not a collection key.
|
||||
if (
|
||||
props.allowsCustomValue &&
|
||||
props.selectionMode === "single" &&
|
||||
typed
|
||||
)
|
||||
request([typed]);
|
||||
return;
|
||||
}
|
||||
if (props.selectionMode === "multiple") {
|
||||
// Confirming the active row toggles it inside the accepted set.
|
||||
const next = keys.value.includes(key)
|
||||
|
||||
@@ -64,6 +64,28 @@ describe("Autocomplete docs and demos", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("uses the baseline search field shell and empty state in every demo", () => {
|
||||
for (const name of previews) {
|
||||
const source = readFileSync(
|
||||
`apps/docs/demos/autocomplete-${name}.vue`,
|
||||
"utf8",
|
||||
);
|
||||
// Upstream renders SearchField autoFocus name="search" variant="secondary"
|
||||
// with a clear button; the popover filter must keep that whole shell.
|
||||
const fields = [...source.matchAll(/<SearchField\b[^>]*>/g)];
|
||||
expect(fields.length, name).toBeGreaterThan(0);
|
||||
for (const [tag] of fields) {
|
||||
expect(tag, name).toMatch(/\bvariant="secondary"/);
|
||||
expect(tag, name).toMatch(/\bname="search"/);
|
||||
expect(tag, name).toMatch(/\bauto-focus/);
|
||||
}
|
||||
expect(source, name).toContain("SearchFieldClearButton");
|
||||
// The ported .hv-empty-state padding must not be overridden per demo.
|
||||
expect(source, name).not.toMatch(/<EmptyState\s+class=/);
|
||||
expect(source, name).not.toContain("alert(");
|
||||
}
|
||||
});
|
||||
|
||||
it("documents Vue props instead of React ones", () => {
|
||||
const document = readFileSync(
|
||||
"apps/docs/components/autocomplete.md",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { defineComponent, h, nextTick, ref, type Component } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
@@ -664,3 +665,31 @@ describe("Autocomplete composition", () => {
|
||||
expect(valueText()).toBe("选择州/省");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Autocomplete ported style hooks", () => {
|
||||
it("emits the data-slot values the ported CSS targets", async () => {
|
||||
const css = readFileSync(
|
||||
"packages/styles/components/autocomplete.css",
|
||||
"utf8",
|
||||
);
|
||||
|
||||
// Only class names carry the hv- prefix: data-slot values are a DOM
|
||||
// contract, so a prefixed value would leave the ported rules dead.
|
||||
expect(css).not.toMatch(/data-slot="hv-/);
|
||||
expect(css).toContain('&[data-slot="autocomplete-default-indicator"]');
|
||||
expect(css).toContain('[data-slot="autocomplete-clear-button-icon"]');
|
||||
|
||||
track(shell({ defaultValue: "texas" }));
|
||||
await nextTick();
|
||||
await settle();
|
||||
|
||||
expect(
|
||||
document.querySelector(
|
||||
'[data-slot="autocomplete-indicator"] [data-slot="autocomplete-default-indicator"]',
|
||||
),
|
||||
).not.toBeNull();
|
||||
expect(
|
||||
document.querySelector('[data-slot="autocomplete-clear-button-icon"]'),
|
||||
).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
+59
-1
@@ -1,5 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { defineComponent, h, nextTick, ref } from "vue";
|
||||
import {
|
||||
ComboBox,
|
||||
@@ -216,7 +217,36 @@ describe("ComboBox input semantics", () => {
|
||||
await press("ArrowDown");
|
||||
await press("Enter");
|
||||
await type("独角兽");
|
||||
expect(onChange).not.toHaveBeenLastCalledWith(null);
|
||||
// Typing a non-matching value must not clear the accepted custom text.
|
||||
expect(onChange).toHaveBeenLastCalledWith("cat");
|
||||
expect(input().value).toBe("独角兽");
|
||||
});
|
||||
|
||||
it("commits a typed custom value with Enter", async () => {
|
||||
const onChange = vi.fn();
|
||||
mountCombo({ allowsCustomValue: true, onSelectionChange: onChange });
|
||||
await nextTick();
|
||||
input().focus();
|
||||
await type("独角兽");
|
||||
await press("Enter");
|
||||
|
||||
// The typed text itself becomes the value, like the baseline.
|
||||
expect(onChange).toHaveBeenLastCalledWith("独角兽");
|
||||
expect(input().value).toBe("独角兽");
|
||||
expect(input().getAttribute("aria-expanded")).toBe("false");
|
||||
});
|
||||
|
||||
it("commits the typed text when the filter excluded every record", async () => {
|
||||
const onChange = vi.fn();
|
||||
mountCombo({ allowsCustomValue: true, onSelectionChange: onChange });
|
||||
await nextTick();
|
||||
input().focus();
|
||||
await press("ArrowDown");
|
||||
// The accepted row is filtered out, so the custom text must still commit.
|
||||
await type("独角兽");
|
||||
await press("Enter");
|
||||
|
||||
expect(onChange).toHaveBeenLastCalledWith("独角兽");
|
||||
expect(input().value).toBe("独角兽");
|
||||
});
|
||||
});
|
||||
@@ -655,3 +685,31 @@ describe("ComboBox menu trigger", () => {
|
||||
expect(input().getAttribute("aria-expanded")).toBe("true");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ComboBox ported style hooks", () => {
|
||||
it("emits the data-slot values the ported CSS targets", async () => {
|
||||
const css = readFileSync(
|
||||
"packages/styles/components/combo-box.css",
|
||||
"utf8",
|
||||
);
|
||||
|
||||
// Only class names carry the hv- prefix: data-slot values are a DOM
|
||||
// contract, so a prefixed value would leave the ported rules dead.
|
||||
expect(css).not.toMatch(/data-slot="hv-/);
|
||||
expect(css).toContain(
|
||||
'&[data-open="true"] [data-slot="combo-box-trigger-default-icon"]',
|
||||
);
|
||||
|
||||
mountCombo();
|
||||
await nextTick();
|
||||
input().focus();
|
||||
await nextTick();
|
||||
await settle();
|
||||
|
||||
const trigger = document.querySelector('[data-slot="combo-box-trigger"]')!;
|
||||
expect(trigger.getAttribute("data-open")).toBe("true");
|
||||
expect(
|
||||
trigger.querySelector('[data-slot="combo-box-trigger-default-icon"]'),
|
||||
).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user