feat(autocomplete): migrate Autocomplete with popover-owned filtering
Port the fixed-baseline Autocomplete onto the B02a collection protocol. The trigger is the single Tab entry; opening moves focus to the search box inside the popover, which owns filtering, aria-activedescendant and keyboard navigation while the list only tracks an active row. - Seven parts: root (field, value/open models, form value, owner wiring), trigger (anchor + activation), value (scoped slot with selectedItems and selectedText instead of copied item subtrees), indicator, clear button, popover (measured trigger width), filter (owns the search text and composes the inner SearchFieldInput into the combobox control). - Filter exposes input-value/update:inputValue/inputChange, matching ComboBox. - Confirming the active row in multiple mode now toggles it instead of replacing the accepted set (ComboBox shared the same bug). - ComboBox shows the accepted label on the first render via a display value that falls back to the selected record, so preselected fields are readable before the selection watcher runs (including SSR). - Popovers measure the anchor with a ResizeObserver because Reka does not publish the anchor size; the caller's root class is merged again so the trigger fills the field width. - 24 baseline previews, Chinese doc page, navigation, 17 behaviour tests, 5 demo/document contracts and an independent tarball consumption script for both pickers. Not included: the full bundler/NodeNext type matrix (B02d).
This commit is contained in:
@@ -25,6 +25,11 @@ export const componentItems: DocsItem[] = [
|
||||
url: "/components/alert-dialog",
|
||||
category: "overlays",
|
||||
},
|
||||
{
|
||||
title: "Autocomplete 自动完成",
|
||||
url: "/components/autocomplete",
|
||||
category: "pickers",
|
||||
},
|
||||
{
|
||||
title: "Avatar 头像",
|
||||
url: "/components/avatar",
|
||||
|
||||
@@ -0,0 +1,439 @@
|
||||
---
|
||||
title: Autocomplete 自动完成
|
||||
description: 结合选择与过滤,让用户从选项列表中搜索并选择
|
||||
component: autocomplete
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete class="w-[256px]" placeholder="选择州/省">
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem id="california" text-value="California">
|
||||
California
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="Texas">Texas</ListBoxItem>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="autocomplete-default" />
|
||||
|
||||
触发器是唯一 Tab 入口;打开后焦点进入弹层内的搜索框,由它负责过滤、`aria-activedescendant` 与方向键导航,列表只维护活动行。
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Description,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete placeholder="选择一项">
|
||||
<Label>分类</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<Description>说明</Description>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索分类">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem id="news" text-value="资讯">
|
||||
资讯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
```
|
||||
|
||||
上游的对象式子部件 `Autocomplete.Trigger` / `.Value` / `.Indicator` / `.Popover` / `.Filter` / `.ClearButton` 在本库中是具名导出 `AutocompleteTrigger` / `AutocompleteValue` / `AutocompleteIndicator` / `AutocompletePopover` / `AutocompleteFilter` / `AutocompleteClearButton`。
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
Autocomplete 支持两种视觉变体:`primary`(默认,带阴影)与 `secondary`(低强调、无阴影,适用于 Surface 内)。
|
||||
|
||||
<ComponentPreview name="autocomplete-variants" />
|
||||
|
||||
### 宽度充满
|
||||
|
||||
<ComponentPreview name="autocomplete-full-width" />
|
||||
|
||||
### 带描述
|
||||
|
||||
<ComponentPreview name="autocomplete-with-description" />
|
||||
|
||||
### 必填
|
||||
|
||||
<ComponentPreview name="autocomplete-required" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="autocomplete-disabled" />
|
||||
|
||||
### 含禁用选项
|
||||
|
||||
<ComponentPreview name="autocomplete-with-disabled-options" />
|
||||
|
||||
### 允许空选项
|
||||
|
||||
`allows-empty-collection` 允许集合为空时仍可打开并交互。
|
||||
|
||||
<ComponentPreview name="autocomplete-allows-empty-collection" />
|
||||
|
||||
### 分组选项
|
||||
|
||||
<ComponentPreview name="autocomplete-with-sections" />
|
||||
|
||||
### 多选
|
||||
|
||||
<ComponentPreview name="autocomplete-multiple-select" />
|
||||
|
||||
上游提醒:多选时 `Autocomplete.Value` 默认会把每个选中项在 `ListBox.Item` 中的子树复制到触发器里。本库不复制子树,而是给 `AutocompleteValue` 的作用域插槽提供 `selectedItems`(`{ key, textValue }[]`)与 `selectedText`(纯文本),由调用方决定渲染纯文本还是标签:
|
||||
|
||||
```vue
|
||||
<AutocompleteValue>
|
||||
<template #default="{ isPlaceholder, defaultChildren, selectedText }">
|
||||
{{ isPlaceholder ? defaultChildren : selectedText }}
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
```
|
||||
|
||||
需要可移除标签时用 `selectedItems` 自行渲染,示例见「多选」。
|
||||
|
||||
### 受控组件
|
||||
|
||||
<ComponentPreview name="autocomplete-controlled" />
|
||||
|
||||
### 受控多选
|
||||
|
||||
<ComponentPreview name="autocomplete-controlled-multiple" />
|
||||
|
||||
### 受控展开状态
|
||||
|
||||
<ComponentPreview name="autocomplete-controlled-open-state" />
|
||||
|
||||
### 异步搜索
|
||||
|
||||
<ComponentPreview name="autocomplete-asynchronous-filtering" />
|
||||
|
||||
### 自定义指示器
|
||||
|
||||
<ComponentPreview name="autocomplete-custom-indicator" />
|
||||
|
||||
### 自定义展示值
|
||||
|
||||
用 `AutocompleteValue` 的作用域插槽自定义展示值。
|
||||
|
||||
<ComponentPreview name="autocomplete-custom-value" />
|
||||
|
||||
### 表面样式
|
||||
|
||||
在 Surface 内使用时请用 `variant="secondary"`。
|
||||
|
||||
<ComponentPreview name="autocomplete-on-surface" />
|
||||
|
||||
### 虚拟滚动
|
||||
|
||||
集合使用 `ListBox` 的 `items` + `virtualized` + `row-height` 渲染可见窗口,仅挂载视口内的行。
|
||||
|
||||
<ComponentPreview name="autocomplete-virtualization" />
|
||||
|
||||
## 高级示例
|
||||
|
||||
### 用户选择
|
||||
|
||||
<ComponentPreview name="autocomplete-user-selection" />
|
||||
|
||||
### 用户多选
|
||||
|
||||
<ComponentPreview name="autocomplete-user-selection-multiple" />
|
||||
|
||||
### 地点搜索
|
||||
|
||||
<ComponentPreview name="autocomplete-location-search" />
|
||||
|
||||
### 标签组选择
|
||||
|
||||
<ComponentPreview name="autocomplete-tag-group-selection" />
|
||||
|
||||
### 邮件收件人
|
||||
|
||||
<ComponentPreview name="autocomplete-email-recipients" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="autocomplete-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
可使用 `@layer components` 指令自定义 Autocomplete 组件类。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-autocomplete {
|
||||
@apply flex flex-col gap-1;
|
||||
}
|
||||
|
||||
.hv-autocomplete__trigger {
|
||||
@apply rounded-lg border border-border bg-surface p-2;
|
||||
}
|
||||
|
||||
.hv-autocomplete__value {
|
||||
@apply text-current;
|
||||
}
|
||||
|
||||
.hv-autocomplete__clear-button {
|
||||
@apply text-muted hover:text-foreground;
|
||||
}
|
||||
|
||||
.hv-autocomplete__indicator {
|
||||
@apply text-muted;
|
||||
}
|
||||
|
||||
.hv-autocomplete__popover {
|
||||
@apply rounded-lg border border-border bg-surface p-2;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/autocomplete.css)):
|
||||
|
||||
#### 基础类
|
||||
|
||||
- `.hv-autocomplete` - 根容器
|
||||
- `.hv-autocomplete__trigger` - 展示值并打开弹层的容器
|
||||
- `.hv-autocomplete__value` - 值或占位符
|
||||
- `.hv-autocomplete__clear-button` - 清除已选值的按钮
|
||||
- `.hv-autocomplete__indicator` - 下拉指示图标
|
||||
- `.hv-autocomplete__popover` - 弹层容器
|
||||
- `.hv-autocomplete__filter` - 过滤包装器
|
||||
|
||||
#### 变体类
|
||||
|
||||
- `.hv-autocomplete--primary` - 带阴影的主变体(默认)
|
||||
- `.hv-autocomplete--secondary` - 无阴影的次变体
|
||||
|
||||
#### 状态类
|
||||
|
||||
- `.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°
|
||||
|
||||
### 交互状态
|
||||
|
||||
- **Hover**:触发器上 `:hover` 或 `[data-hovered="true"]`
|
||||
- **Focus**:触发器与搜索框上 `:focus-visible`
|
||||
- **Disabled**:根与触发器上 `[data-disabled="true"]`
|
||||
- **Open**:触发器上 `[data-open="true"]`、指示器上 `[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 绑定) |
|
||||
|
||||
事件:
|
||||
|
||||
| 事件 | 载荷 | 描述 |
|
||||
| ------------------- | ----------------------------------- | ------------ |
|
||||
| `update:modelValue` | `string \| number \| Array \| null` | 值变化 |
|
||||
| `change` | 同上 | 值变化 |
|
||||
| `update:open` | `boolean` | 弹层开关变化 |
|
||||
| `openChange` | `boolean` | 弹层开关变化 |
|
||||
| `clear` | - | 清除已选值 |
|
||||
|
||||
### AutocompleteTrigger
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------- | --------------------------- | ------- | -------------------------------------------------------- |
|
||||
| `is-disabled` | `boolean` | `false` | 是否禁用触发器 |
|
||||
| 默认插槽 | `Component` | - | 通常为 `AutocompleteValue` + `ClearButton` + `Indicator` |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
触发器渲染为 `role="button"` 的可点击容器,是组件唯一的 Tab 入口(`tabindex="0"`;禁用时 `-1`),`Enter` / `Space` / `ArrowDown` 打开,`Escape` 关闭,`Delete` / `Backspace` 清除。
|
||||
|
||||
### AutocompleteValue
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | ----------------------------------------------------------------- | ------ | ----------------------------- |
|
||||
| 默认插槽 | `{ isPlaceholder, defaultChildren, selectedText, selectedItems }` | - | 自定义展示值 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### AutocompleteIndicator
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | -------------------------------- |
|
||||
| 默认插槽 | `Component` | - | 自定义指示器图形(默认为下箭头) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
指示器是装饰元素(`aria-hidden`),激活由触发器负责。
|
||||
|
||||
### AutocompleteClearButton
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||||
| 默认插槽 | `Component` | - | 自定义清除图标 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
`aria-label` 默认 `Clear selection`,`tabindex="-1"`,无选择时 `data-empty="true"` 并隐藏。
|
||||
|
||||
### 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 绑定) |
|
||||
|
||||
宽度跟随触发器(`--trigger-width`)。
|
||||
|
||||
### AutocompleteFilter
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------------------- | ------------------------------- | ---------------------- | ------------------------------------------------------------- |
|
||||
| `filter` | `(text, inputValue) => boolean` | 不区分大小写的包含匹配 | 自定义过滤函数 |
|
||||
| `input-value` | `string` | - | 受控搜索文本 |
|
||||
| `default-input-value` | `string` | `''` | 非受控初始搜索文本 |
|
||||
| 默认插槽 | `Component` | - | 必须包含 `SearchField`(内含 `SearchFieldInput`)与 `ListBox` |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
过滤文本由 `AutocompleteFilter` 拥有,并通过集合的过滤协议影响列表的显示与键盘导航;它不会清除已接受的选择。
|
||||
|
||||
受控文本用 `:input-value` + `@input-change`(或 `v-model:input-value`):
|
||||
|
||||
| 事件 | 载荷 | 描述 |
|
||||
| ------------------- | -------- | ------------ |
|
||||
| `update:inputValue` | `string` | 搜索文本变化 |
|
||||
| `inputChange` | `string` | 搜索文本变化 |
|
||||
|
||||
### 作用域插槽与渲染信息
|
||||
|
||||
`AutocompleteValue` 的默认插槽提供:
|
||||
|
||||
| 字段 | 类型 | 描述 |
|
||||
| ----------------- | --------------------------- | -------------------------------------------- |
|
||||
| `isPlaceholder` | `boolean` | 是否没有选中项 |
|
||||
| `defaultChildren` | `string` | 缺省文本(选中项文本以逗号连接,否则占位符) |
|
||||
| `selectedText` | `string` | 选中项 `textValue` 的连接文本 |
|
||||
| `selectedItems` | `Array<{ key, textValue }>` | 选中项 |
|
||||
|
||||
上游 `state.selectedItems`(节点)在本库中是上表的 `selectedItems`(数据);不复制 item 子树,见「多选」说明。
|
||||
|
||||
## 无障碍
|
||||
|
||||
Autocomplete 实现带过滤的 ARIA select 模式:
|
||||
|
||||
- 触发器是唯一 Tab 入口,并带 `aria-haspopup="listbox"` / `aria-expanded` / `aria-controls`
|
||||
- 打开后焦点进入弹层内搜索框(`role="combobox"`),`aria-activedescendant` 指向已挂载且可见的活动选项
|
||||
- `ArrowDown` / `ArrowUp` / `Home` / `End` 在过滤后的可见集合中移动,`Enter` 确认,`Escape` 关闭,`Tab` 离开
|
||||
- 中文输入法组合期间不确认选择(`isComposing` / `keyCode 229` 时忽略键盘提交)
|
||||
- 过滤不会清除已接受的选择;关闭后焦点回到触发器,弹层内不出现第二个 Tab 入口
|
||||
|
||||
## 相关组件
|
||||
|
||||
[ComboBox 组合框](./combo-box) · [Select 选择器](./select) · [ListBox 列表框](./list-box) · [SearchField 搜索框](./search-field)
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
allows-empty-collection
|
||||
class="w-[256px]"
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,153 @@
|
||||
<!-- 适配:源示例请求 SWAPI,这里用本地异步源演示相同状态(取消旧请求、加载中、空状态)。 -->
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Spinner,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
type Character = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
const SEARCH_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: "波巴·费特" },
|
||||
];
|
||||
|
||||
const query = ref("");
|
||||
const results = ref<Character[]>([]);
|
||||
const loading = ref(false);
|
||||
let controller: AbortController | undefined;
|
||||
|
||||
function match(text: string) {
|
||||
const search = text.trim().toLocaleLowerCase();
|
||||
|
||||
return characters.filter(
|
||||
(character) =>
|
||||
!search || character.name.toLocaleLowerCase().includes(search),
|
||||
);
|
||||
}
|
||||
|
||||
function runSearch(text: string) {
|
||||
// 每次查询一个 AbortController:新输入会取消上一个请求,迟到的结果不再写回。
|
||||
controller?.abort();
|
||||
const current = new AbortController();
|
||||
|
||||
controller = current;
|
||||
loading.value = true;
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
if (current.signal.aborted) return;
|
||||
|
||||
results.value = match(text);
|
||||
if (controller === current) loading.value = false;
|
||||
}, SEARCH_DELAY);
|
||||
|
||||
current.signal.addEventListener("abort", () => clearTimeout(timer), {
|
||||
once: true,
|
||||
});
|
||||
}
|
||||
|
||||
// 受控文本:AutocompleteFilter 通过 input-value / input-change 暴露搜索文本。
|
||||
function setQuery(value: string) {
|
||||
query.value = value;
|
||||
runSearch(value);
|
||||
}
|
||||
|
||||
onMounted(() => runSearch(""));
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
controller?.abort();
|
||||
controller = undefined;
|
||||
});
|
||||
|
||||
// 结果集已由异步源过滤,集合不再按输入文本二次过滤。
|
||||
const keepResults = () => true;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
allows-empty-collection
|
||||
class="w-[256px]"
|
||||
placeholder="搜索…"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>搜索《星球大战》角色</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter
|
||||
:filter="keepResults"
|
||||
:input-value="query"
|
||||
@input-change="setQuery"
|
||||
>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索角色"
|
||||
class="sticky top-0 z-10"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索角色…" />
|
||||
<Spinner
|
||||
size="sm"
|
||||
:class="[
|
||||
'absolute end-2 top-1/2 -translate-y-1/2',
|
||||
{ 'pointer-events-none opacity-0': !loading },
|
||||
]"
|
||||
/>
|
||||
<SearchFieldClearButton
|
||||
:class="{ 'pointer-events-none opacity-0': loading }"
|
||||
/>
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox :items="results" class="max-h-[420px] overflow-y-auto">
|
||||
<template #default="{ item }">
|
||||
<ListBoxItem :id="item.id" :text-value="item.name">
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</template>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,78 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const items = [
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "illinois", name: "Illinois" },
|
||||
{ id: "pennsylvania", name: "Pennsylvania" },
|
||||
];
|
||||
|
||||
const selected = ref<TagKey[]>(["california", "texas"]);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-2">
|
||||
<Autocomplete
|
||||
v-model="selected"
|
||||
class="w-[256px]"
|
||||
placeholder="选择州"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
<p class="text-sm text-muted">
|
||||
已选:{{ selected.length > 0 ? selected.join(", ") : "无" }}
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,82 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Button,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const items = [
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "delaware", name: "Delaware" },
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "washington", name: "Washington" },
|
||||
];
|
||||
|
||||
const isOpen = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-4">
|
||||
<Autocomplete
|
||||
:is-open="isOpen"
|
||||
class="w-[256px]"
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
@open-change="isOpen = $event"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
<Button @click="isOpen = !isOpen">
|
||||
{{ isOpen ? "关闭" : "打开" }} 自动完成
|
||||
</Button>
|
||||
<p class="text-sm text-muted">
|
||||
自动完成处于{{ isOpen ? "打开" : "关闭" }}状态
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,79 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const states = [
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "illinois", name: "Illinois" },
|
||||
{ id: "pennsylvania", name: "Pennsylvania" },
|
||||
];
|
||||
|
||||
const state = ref<string | null>("california");
|
||||
|
||||
const selectedState = computed(() =>
|
||||
states.find((item) => item.id === state.value),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-2">
|
||||
<Autocomplete
|
||||
v-model="state"
|
||||
class="w-[256px]"
|
||||
placeholder="选择一个州"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>州(受控)</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in states"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
<p class="text-sm text-muted">已选:{{ selectedState?.name || "无" }}</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,75 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconSelector } from "@tabler/icons-vue";
|
||||
|
||||
const items = [
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "delaware", name: "Delaware" },
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "washington", name: "Washington" },
|
||||
];
|
||||
|
||||
const selectedKey = ref<string | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
class="w-[256px]"
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator>
|
||||
<IconSelector class="size-3" aria-hidden="true" />
|
||||
</AutocompleteIndicator>
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,126 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const teammates = [
|
||||
{ id: "sarah", name: "Sarah Chen", role: "产品设计" },
|
||||
{ id: "marcus", name: "Marcus Lee", role: "工程" },
|
||||
{ id: "priya", name: "Priya Patel", role: "数据科学" },
|
||||
{ id: "jordan", name: "Jordan Kim", role: "客户成功" },
|
||||
{ id: "alex", name: "Alex Rivera", role: "市场营销" },
|
||||
];
|
||||
|
||||
const selectedKeys = ref<TagKey[]>([]);
|
||||
|
||||
const teammateOf = (key: unknown) =>
|
||||
teammates.find((teammate) => teammate.id === key);
|
||||
|
||||
function onRemoveTags(keys: TagKey[]) {
|
||||
selectedKeys.value = selectedKeys.value.filter((key) => !keys.includes(key));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-full max-w-sm pt-6">
|
||||
<Autocomplete
|
||||
v-model="selectedKeys"
|
||||
class="w-full gap-1.5"
|
||||
placeholder="搜索团队成员..."
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label class="font-medium text-foreground">负责人</Label>
|
||||
<Description>任务更新时将通知以下人员。</Description>
|
||||
<AutocompleteTrigger
|
||||
class="rounded-xl border border-border/80 bg-surface shadow-sm ring-1 ring-accent/5 transition-[box-shadow,border-color] focus-within:border-accent/25 focus-within:ring-2 focus-within:ring-accent/15 dark:border-border/90 dark:bg-surface dark:ring-accent/10 dark:focus-within:border-accent/35"
|
||||
>
|
||||
<AutocompleteValue>
|
||||
<template
|
||||
#default="{ defaultChildren, isPlaceholder, selectedItems }"
|
||||
>
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup v-else size="sm" @remove="onRemoveTags">
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="teammateOf(item.key)?.name"
|
||||
class="border border-accent/15 bg-accent/8 text-foreground dark:border-accent/25 dark:bg-accent/12"
|
||||
>
|
||||
{{ teammateOf(item.key)?.name }}
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover
|
||||
class="overflow-hidden rounded-xl border border-border/80 bg-surface shadow-xl ring-1 ring-black/3 dark:border-border/90 dark:bg-surface dark:ring-white/5"
|
||||
>
|
||||
<AutocompleteFilter>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="按姓名或角色搜索"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup
|
||||
class="border-b border-separator bg-surface-secondary/50"
|
||||
>
|
||||
<SearchFieldSearchIcon class="text-muted" />
|
||||
<SearchFieldInput placeholder="按姓名或角色搜索..." />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox class="p-1.5">
|
||||
<ListBoxItem
|
||||
v-for="teammate in teammates"
|
||||
:id="teammate.id"
|
||||
:key="teammate.id"
|
||||
:text-value="`${teammate.name} ${teammate.role}`"
|
||||
class="rounded-lg data-[focused=true]:bg-accent/10 data-[selected=true]:bg-accent/5 dark:data-[focused=true]:bg-accent/15 dark:data-[selected=true]:bg-accent/8"
|
||||
>
|
||||
<div class="flex flex-col gap-0.5">
|
||||
<span class="text-sm font-medium text-foreground">
|
||||
{{ teammate.name }}
|
||||
</span>
|
||||
<span class="text-xs text-muted">{{ teammate.role }}</span>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到团队成员</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,98 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const currencies = [
|
||||
{ code: "USD", id: "usd", name: "美元", symbol: "$" },
|
||||
{ code: "EUR", id: "eur", name: "欧元", symbol: "€" },
|
||||
{ code: "GBP", id: "gbp", name: "英镑", symbol: "£" },
|
||||
{ code: "JPY", id: "jpy", name: "日元", symbol: "¥" },
|
||||
{ code: "CHF", id: "chf", name: "瑞士法郎", symbol: "₣" },
|
||||
];
|
||||
|
||||
const currencyOf = (key: unknown) =>
|
||||
currencies.find((currency) => currency.id === key);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
class="w-[256px]"
|
||||
default-value="usd"
|
||||
placeholder="选择货币"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>货币</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<span
|
||||
v-if="isPlaceholder || !currencyOf(selectedItems[0]?.key)"
|
||||
class="flex min-w-0 items-center gap-1.5"
|
||||
>
|
||||
{{ defaultChildren }}
|
||||
</span>
|
||||
<span v-else class="flex min-w-0 items-center gap-1.5">
|
||||
<span class="font-medium">
|
||||
{{ currencyOf(selectedItems[0]?.key)?.symbol }}
|
||||
</span>
|
||||
<span>{{ currencyOf(selectedItems[0]?.key)?.code }}</span>
|
||||
<span class="truncate text-muted">
|
||||
{{ currencyOf(selectedItems[0]?.key)?.name }}
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索货币"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索货币…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="currency in currencies"
|
||||
:id="currency.id"
|
||||
:key="currency.id"
|
||||
:text-value="`${currency.code} ${currency.name}`"
|
||||
>
|
||||
<div class="flex flex-col">
|
||||
<Label>{{ currency.code }}</Label>
|
||||
<Description>{{ currency.name }}</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,97 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const states = [
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "delaware", name: "Delaware" },
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "washington", name: "Washington" },
|
||||
];
|
||||
|
||||
const selectedKeys = ref<TagKey[]>([]);
|
||||
|
||||
function onRemoveTags(keys: TagKey[]) {
|
||||
selectedKeys.value = selectedKeys.value.filter((key) => !keys.includes(key));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKeys"
|
||||
class="w-[256px]"
|
||||
placeholder="选择州/省"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>计划前往的州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup v-else size="sm" @remove="onRemoveTags">
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="item.textValue"
|
||||
>
|
||||
{{ item.textValue }}
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="state in states"
|
||||
:id="state.id"
|
||||
:key="state.id"
|
||||
:text-value="state.name"
|
||||
>
|
||||
{{ state.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,119 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const items = [
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "delaware", name: "Delaware" },
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "washington", name: "Washington" },
|
||||
];
|
||||
|
||||
const countries = [
|
||||
{ id: "argentina", name: "Argentina" },
|
||||
{ id: "venezuela", name: "Venezuela" },
|
||||
{ id: "japan", name: "Japan" },
|
||||
{ id: "france", name: "France" },
|
||||
{ id: "italy", name: "Italy" },
|
||||
{ id: "spain", name: "Spain" },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<Autocomplete
|
||||
is-disabled
|
||||
class="w-[256px]"
|
||||
default-value="california"
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
<Autocomplete
|
||||
is-disabled
|
||||
class="w-[256px]"
|
||||
:default-value="['argentina', 'japan', 'france']"
|
||||
placeholder="选择国家"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>计划前往的国家</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索国家">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索国家…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="country in countries"
|
||||
:id="country.id"
|
||||
:key="country.id"
|
||||
:text-value="country.name"
|
||||
>
|
||||
{{ country.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,116 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const emails = [
|
||||
{
|
||||
email: "alice@example.com",
|
||||
id: "alice@example.com",
|
||||
name: "Alice Johnson",
|
||||
},
|
||||
{ email: "bob@example.com", id: "bob@example.com", name: "Bob Smith" },
|
||||
{
|
||||
email: "charlie@example.com",
|
||||
id: "charlie@example.com",
|
||||
name: "Charlie Brown",
|
||||
},
|
||||
{ email: "diana@example.com", id: "diana@example.com", name: "Diana Prince" },
|
||||
{ email: "eve@example.com", id: "eve@example.com", name: "Eve Wilson" },
|
||||
];
|
||||
|
||||
const selectedKeys = ref<TagKey[]>([]);
|
||||
|
||||
function onRemoveTags(keys: TagKey[]) {
|
||||
selectedKeys.value = selectedKeys.value.filter((key) => !keys.includes(key));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKeys"
|
||||
class="w-[256px]"
|
||||
placeholder="添加收件人"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>收件人</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup v-else size="sm" @remove="onRemoveTags">
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="item.textValue"
|
||||
>
|
||||
{{ item.textValue }}
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索邮箱"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索邮箱…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="entry in emails"
|
||||
:id="entry.id"
|
||||
:key="entry.id"
|
||||
:text-value="entry.email"
|
||||
>
|
||||
<div class="flex flex-col">
|
||||
<Label>{{ entry.name }}</Label>
|
||||
<Description>{{ entry.email }}</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到收件人</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,76 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Surface,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const items = [
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "delaware", name: "Delaware" },
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "washington", name: "Washington" },
|
||||
];
|
||||
|
||||
const selectedKey = ref<string | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Surface class="w-[380px] space-y-4 rounded-3xl p-6">
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
full-width
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
variant="secondary"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</Surface>
|
||||
</template>
|
||||
@@ -0,0 +1,114 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
type City = {
|
||||
name: string;
|
||||
country: string;
|
||||
};
|
||||
|
||||
const allCities: City[] = [
|
||||
{ country: "美国", name: "纽约" },
|
||||
{ country: "美国", name: "洛杉矶" },
|
||||
{ country: "美国", name: "芝加哥" },
|
||||
{ country: "英国", name: "伦敦" },
|
||||
{ country: "法国", name: "巴黎" },
|
||||
{ country: "日本", name: "东京" },
|
||||
{ country: "澳大利亚", name: "悉尼" },
|
||||
{ country: "加拿大", name: "多伦多" },
|
||||
{ country: "德国", name: "柏林" },
|
||||
{ country: "西班牙", name: "马德里" },
|
||||
];
|
||||
|
||||
const selectedKey = ref<string | null>(null);
|
||||
const loading = ref(false);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const contains = (text: string, input: string) =>
|
||||
text.toLocaleLowerCase().includes(input.toLocaleLowerCase());
|
||||
|
||||
// 源示例在过滤回调里模拟异步搜索:先标记加载中,300ms 后结束。
|
||||
function customFilter(text: string, input: string) {
|
||||
if (!input) return true;
|
||||
|
||||
loading.value = true;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
loading.value = false;
|
||||
}, 300);
|
||||
|
||||
return contains(text, input);
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => clearTimeout(timer));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
class="w-[256px]"
|
||||
placeholder="搜索城市"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>城市</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter :filter="customFilter">
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索城市"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索城市…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="city in allCities"
|
||||
:id="city.name"
|
||||
:key="city.name"
|
||||
:text-value="`${city.name} ${city.country}`"
|
||||
>
|
||||
<div class="flex flex-col">
|
||||
<Label>{{ city.name }}</Label>
|
||||
<Description>{{ city.country }}</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">
|
||||
{{ loading ? "搜索中…" : "未找到城市" }}
|
||||
</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,98 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const states = [
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "illinois", name: "Illinois" },
|
||||
{ id: "pennsylvania", name: "Pennsylvania" },
|
||||
];
|
||||
|
||||
const selectedKeys = ref<TagKey[]>([]);
|
||||
|
||||
function onRemoveTags(keys: TagKey[]) {
|
||||
selectedKeys.value = selectedKeys.value.filter((key) => !keys.includes(key));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKeys"
|
||||
class="w-[256px]"
|
||||
placeholder="选择州/省"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup v-else size="sm" @remove="onRemoveTags">
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="item.textValue"
|
||||
>
|
||||
{{ item.textValue }}
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="state in states"
|
||||
:id="state.id"
|
||||
:key="state.id"
|
||||
:text-value="state.name"
|
||||
>
|
||||
{{ state.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,83 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Surface,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const items = [
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "delaware", name: "Delaware" },
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "washington", name: "Washington" },
|
||||
];
|
||||
|
||||
const selectedKey = ref<string | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Surface class="w-[320px] rounded-3xl p-6">
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
class="w-full"
|
||||
placeholder="选择一个"
|
||||
selection-mode="single"
|
||||
variant="secondary"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索州名"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</Surface>
|
||||
</template>
|
||||
@@ -0,0 +1,137 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Button,
|
||||
EmptyState,
|
||||
FieldError,
|
||||
Form,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const states = [
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "delaware", name: "Delaware" },
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "washington", name: "Washington" },
|
||||
];
|
||||
|
||||
const countries = [
|
||||
{ id: "usa", name: "United States" },
|
||||
{ id: "canada", name: "Canada" },
|
||||
{ id: "mexico", name: "Mexico" },
|
||||
{ id: "uk", name: "United Kingdom" },
|
||||
{ id: "france", name: "France" },
|
||||
{ id: "germany", name: "Germany" },
|
||||
];
|
||||
|
||||
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")}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Form class="flex w-[256px] flex-col gap-4" @submit="onSubmit">
|
||||
<Autocomplete
|
||||
is-required
|
||||
class="w-full"
|
||||
name="state"
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="state in states"
|
||||
:id="state.id"
|
||||
:key="state.id"
|
||||
:text-value="state.name"
|
||||
>
|
||||
{{ state.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
<FieldError />
|
||||
</Autocomplete>
|
||||
<Autocomplete
|
||||
is-required
|
||||
class="w-full"
|
||||
name="country"
|
||||
placeholder="选择一个国家"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>国家</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索国家">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索国家…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="country in countries"
|
||||
:id="country.id"
|
||||
:key="country.id"
|
||||
:text-value="country.name"
|
||||
>
|
||||
{{ country.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
<FieldError />
|
||||
</Autocomplete>
|
||||
<Button type="submit">提交</Button>
|
||||
<p v-if="message" role="status" class="text-sm text-success">
|
||||
{{ message }}
|
||||
</p>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,107 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const tags = [
|
||||
{ id: "react", name: "React" },
|
||||
{ id: "typescript", name: "TypeScript" },
|
||||
{ id: "javascript", name: "JavaScript" },
|
||||
{ id: "nodejs", name: "Node.js" },
|
||||
{ id: "python", name: "Python" },
|
||||
{ id: "vue", name: "Vue" },
|
||||
{ id: "angular", name: "Angular" },
|
||||
{ id: "nextjs", name: "Next.js" },
|
||||
];
|
||||
|
||||
const selectedKeys = ref<TagKey[]>([]);
|
||||
|
||||
function onRemoveTags(keys: TagKey[]) {
|
||||
selectedKeys.value = selectedKeys.value.filter((key) => !keys.includes(key));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKeys"
|
||||
class="w-[256px]"
|
||||
placeholder="选择标签"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>标签</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup v-else size="sm" @remove="onRemoveTags">
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="item.textValue"
|
||||
>
|
||||
{{ item.textValue }}
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索标签"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索标签…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="tag in tags"
|
||||
:id="tag.id"
|
||||
:key="tag.id"
|
||||
:text-value="tag.name"
|
||||
>
|
||||
{{ tag.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到标签</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,158 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Avatar,
|
||||
AvatarFallback,
|
||||
AvatarImage,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const users = [
|
||||
{
|
||||
id: "1",
|
||||
name: "Bob",
|
||||
email: "bob@heroui.com",
|
||||
fallback: "B",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg",
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
name: "Fred",
|
||||
email: "fred@heroui.com",
|
||||
fallback: "F",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg",
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
name: "Martha",
|
||||
email: "martha@heroui.com",
|
||||
fallback: "M",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg",
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
name: "John",
|
||||
email: "john@heroui.com",
|
||||
fallback: "J",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg",
|
||||
},
|
||||
{
|
||||
id: "5",
|
||||
name: "Jane",
|
||||
email: "jane@heroui.com",
|
||||
fallback: "J",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg",
|
||||
},
|
||||
];
|
||||
|
||||
const selectedKeys = ref<TagKey[]>(["1", "2"]);
|
||||
|
||||
const userOf = (key: unknown) => users.find((user) => user.id === key);
|
||||
|
||||
function onRemoveTags(keys: TagKey[]) {
|
||||
selectedKeys.value = selectedKeys.value.filter((key) => !keys.includes(key));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKeys"
|
||||
class="w-[256px]"
|
||||
placeholder="选择队友"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>用户</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup v-else size="sm" @remove="onRemoveTags">
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="item.textValue"
|
||||
>
|
||||
<Avatar class="size-4" size="sm">
|
||||
<AvatarImage :src="userOf(item.key)?.avatarUrl ?? ''" />
|
||||
<AvatarFallback>
|
||||
{{ userOf(item.key)?.fallback }}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<span>{{ item.textValue }}</span>
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索用户"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索用户…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="user in users"
|
||||
:id="user.id"
|
||||
:key="user.id"
|
||||
:text-value="user.name"
|
||||
>
|
||||
<Avatar size="sm">
|
||||
<AvatarImage :src="user.avatarUrl" />
|
||||
<AvatarFallback>{{ user.fallback }}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div class="flex flex-col">
|
||||
<Label>{{ user.name }}</Label>
|
||||
<Description>{{ user.email }}</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,146 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Avatar,
|
||||
AvatarFallback,
|
||||
AvatarImage,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const users = [
|
||||
{
|
||||
id: "1",
|
||||
name: "Bob",
|
||||
email: "bob@heroui.com",
|
||||
fallback: "B",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg",
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
name: "Fred",
|
||||
email: "fred@heroui.com",
|
||||
fallback: "F",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg",
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
name: "Martha",
|
||||
email: "martha@heroui.com",
|
||||
fallback: "M",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg",
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
name: "John",
|
||||
email: "john@heroui.com",
|
||||
fallback: "J",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg",
|
||||
},
|
||||
{
|
||||
id: "5",
|
||||
name: "Jane",
|
||||
email: "jane@heroui.com",
|
||||
fallback: "J",
|
||||
avatarUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg",
|
||||
},
|
||||
];
|
||||
|
||||
const selectedKey = ref<string | null>(null);
|
||||
|
||||
const userOf = (key: unknown) => users.find((user) => user.id === key);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
class="w-[256px]"
|
||||
placeholder="选择用户"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>用户</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template #default="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<template v-else-if="selectedItems.length > 1">
|
||||
已选择 {{ selectedItems.length }} 位用户
|
||||
</template>
|
||||
<div v-else class="flex items-center gap-2">
|
||||
<Avatar class="size-4" size="sm">
|
||||
<AvatarImage
|
||||
:src="userOf(selectedItems[0]?.key)?.avatarUrl ?? ''"
|
||||
/>
|
||||
<AvatarFallback>
|
||||
{{ userOf(selectedItems[0]?.key)?.fallback }}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<span>{{ userOf(selectedItems[0]?.key)?.name }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索用户"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索用户…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="user in users"
|
||||
:id="user.id"
|
||||
:key="user.id"
|
||||
:text-value="user.name"
|
||||
>
|
||||
<Avatar size="sm">
|
||||
<AvatarImage :src="user.avatarUrl" />
|
||||
<AvatarFallback>{{ user.fallback }}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div class="flex flex-col">
|
||||
<Label>{{ user.name }}</Label>
|
||||
<Description>{{ user.email }}</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,261 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
type TagKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const items = [
|
||||
{ id: "option1", name: "选项 1" },
|
||||
{ id: "option2", name: "选项 2" },
|
||||
{ id: "option3", name: "选项 3" },
|
||||
{ id: "option4", name: "选项 4" },
|
||||
];
|
||||
|
||||
const selectedKey1 = ref<string | null>(null);
|
||||
const selectedKey2 = ref<string | null>(null);
|
||||
const selectedKeys1 = ref<TagKey[]>([]);
|
||||
const selectedKeys2 = ref<TagKey[]>([]);
|
||||
|
||||
function onRemoveTags1(keys: TagKey[]) {
|
||||
selectedKeys1.value = selectedKeys1.value.filter(
|
||||
(key) => !keys.includes(key),
|
||||
);
|
||||
}
|
||||
|
||||
function onRemoveTags2(keys: TagKey[]) {
|
||||
selectedKeys2.value = selectedKeys2.value.filter(
|
||||
(key) => !keys.includes(key),
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-8">
|
||||
<div class="flex flex-col gap-4">
|
||||
<h3 class="text-lg font-semibold">单选变体</h3>
|
||||
<div class="flex flex-col gap-4">
|
||||
<Autocomplete
|
||||
v-model="selectedKey1"
|
||||
class="w-[256px]"
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
variant="primary"
|
||||
>
|
||||
<Label>主色(primary)变体</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
<Autocomplete
|
||||
v-model="selectedKey2"
|
||||
class="w-[256px]"
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
variant="secondary"
|
||||
>
|
||||
<Label>次色(secondary)变体</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-4">
|
||||
<h3 class="text-lg font-semibold">多选变体</h3>
|
||||
<div class="flex flex-col gap-4">
|
||||
<Autocomplete
|
||||
v-model="selectedKeys1"
|
||||
class="w-[256px]"
|
||||
placeholder="选择多项"
|
||||
selection-mode="multiple"
|
||||
variant="primary"
|
||||
>
|
||||
<Label>主色(primary)变体</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template
|
||||
#default="{ defaultChildren, isPlaceholder, selectedItems }"
|
||||
>
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup v-else size="sm" @remove="onRemoveTags1">
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="item.textValue"
|
||||
>
|
||||
{{ item.textValue }}
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
<Autocomplete
|
||||
v-model="selectedKeys2"
|
||||
class="w-[256px]"
|
||||
placeholder="选择多项"
|
||||
selection-mode="multiple"
|
||||
variant="secondary"
|
||||
>
|
||||
<Label>次色(secondary)变体</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue>
|
||||
<template
|
||||
#default="{ defaultChildren, isPlaceholder, selectedItems }"
|
||||
>
|
||||
<template v-if="isPlaceholder || selectedItems.length === 0">
|
||||
{{ defaultChildren }}
|
||||
</template>
|
||||
<TagGroup
|
||||
v-else
|
||||
size="sm"
|
||||
variant="surface"
|
||||
@remove="onRemoveTags2"
|
||||
>
|
||||
<TagGroupList>
|
||||
<Tag
|
||||
v-for="item in selectedItems"
|
||||
:id="item.key"
|
||||
:key="item.key"
|
||||
:text-value="item.textValue"
|
||||
>
|
||||
{{ item.textValue }}
|
||||
</Tag>
|
||||
</TagGroupList>
|
||||
</TagGroup>
|
||||
</template>
|
||||
</AutocompleteValue>
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索选项">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,175 @@
|
||||
<!-- 适配:源示例用 Virtualizer + ListLayout 包裹 ListBox,本库 ListBox 直接提供 items + virtualized + row-height 虚拟滚动。 -->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldClearButton,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
type ListBoxKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
type User = {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
const firstNames = [
|
||||
"Emma",
|
||||
"Liam",
|
||||
"Olivia",
|
||||
"Noah",
|
||||
"Ava",
|
||||
"James",
|
||||
"Sophia",
|
||||
"Oliver",
|
||||
"Isabella",
|
||||
"Lucas",
|
||||
"Mia",
|
||||
"Ethan",
|
||||
"Charlotte",
|
||||
"Mason",
|
||||
"Amelia",
|
||||
"Logan",
|
||||
"Harper",
|
||||
"Alexander",
|
||||
"Ella",
|
||||
"Benjamin",
|
||||
];
|
||||
|
||||
const lastNames = [
|
||||
"Smith",
|
||||
"Johnson",
|
||||
"Williams",
|
||||
"Brown",
|
||||
"Jones",
|
||||
"Garcia",
|
||||
"Miller",
|
||||
"Davis",
|
||||
"Rodriguez",
|
||||
"Martinez",
|
||||
"Anderson",
|
||||
"Taylor",
|
||||
"Thomas",
|
||||
"Jackson",
|
||||
"White",
|
||||
"Harris",
|
||||
"Clark",
|
||||
"Lewis",
|
||||
"Robinson",
|
||||
"Walker",
|
||||
];
|
||||
|
||||
function generateUsers(count: number): User[] {
|
||||
const users: User[] = [];
|
||||
|
||||
for (let index = 0; index < count; index++) {
|
||||
const first = firstNames[index % firstNames.length]!;
|
||||
const last =
|
||||
lastNames[Math.floor(index / firstNames.length) % lastNames.length]!;
|
||||
|
||||
users.push({
|
||||
id: index + 1,
|
||||
name: `${first} ${last}`,
|
||||
email: `${first.toLowerCase()}.${last.toLowerCase()}@acme.com`,
|
||||
});
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
const allUsers = generateUsers(1000);
|
||||
const selectedKey = ref<ListBoxKey | null>(null);
|
||||
const searchQuery = ref("");
|
||||
|
||||
const filteredUsers = computed(() => {
|
||||
const query = searchQuery.value.trim().toLocaleLowerCase();
|
||||
|
||||
if (!query) return allUsers;
|
||||
|
||||
return allUsers.filter(
|
||||
(user) =>
|
||||
user.name.toLocaleLowerCase().includes(query) ||
|
||||
user.email.toLocaleLowerCase().includes(query),
|
||||
);
|
||||
});
|
||||
|
||||
function setSearchQuery(value: string) {
|
||||
searchQuery.value = value;
|
||||
}
|
||||
|
||||
// 过滤已在上面的 computed 中完成(姓名或邮箱),集合不再叠加文本过滤。
|
||||
const keepResults = () => true;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
allows-empty-collection
|
||||
class="w-[300px]"
|
||||
placeholder="选择用户"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>用户</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter
|
||||
:filter="keepResults"
|
||||
:input-value="searchQuery"
|
||||
@input-change="setSearchQuery"
|
||||
>
|
||||
<SearchField
|
||||
auto-focus
|
||||
aria-label="搜索用户"
|
||||
class="sticky top-0 z-10"
|
||||
name="search"
|
||||
variant="secondary"
|
||||
>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索用户…" />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox
|
||||
:items="filteredUsers"
|
||||
class="max-h-[320px] overflow-y-auto"
|
||||
:row-height="50"
|
||||
virtualized
|
||||
>
|
||||
<template #default="{ item }">
|
||||
<ListBoxItem :id="item.id" :text-value="item.name" class="h-full">
|
||||
<div class="flex flex-col">
|
||||
<Label>{{ item.name }}</Label>
|
||||
<Description>{{ item.email }}</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</template>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,74 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const items = [
|
||||
{ id: "florida", name: "Florida" },
|
||||
{ id: "delaware", name: "Delaware" },
|
||||
{ id: "california", name: "California" },
|
||||
{ id: "texas", name: "Texas" },
|
||||
{ id: "new-york", name: "New York" },
|
||||
{ id: "washington", name: "Washington" },
|
||||
];
|
||||
|
||||
const selectedKey = ref<string | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
class="w-[256px]"
|
||||
placeholder="请选择一项"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索州名">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索州名…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
<Description>请选择你的居住州</Description>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,73 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const animals = [
|
||||
{ id: "dog", name: "狗" },
|
||||
{ id: "cat", name: "猫" },
|
||||
{ id: "bird", name: "鸟" },
|
||||
{ id: "kangaroo", name: "袋鼠" },
|
||||
{ id: "elephant", name: "象" },
|
||||
{ id: "tiger", name: "老虎" },
|
||||
];
|
||||
|
||||
const selectedKey = ref<string | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
class="w-[256px]"
|
||||
:disabled-keys="['cat', 'kangaroo']"
|
||||
placeholder="选择一种动物"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>动物</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索动物">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索动物…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="animal in animals"
|
||||
:id="animal.id"
|
||||
:key="animal.id"
|
||||
:text-value="animal.name"
|
||||
>
|
||||
{{ animal.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
@@ -0,0 +1,116 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
EmptyState,
|
||||
Header,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
ListBoxSection,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
Separator,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const selectedKey = ref<string | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Autocomplete
|
||||
v-model="selectedKey"
|
||||
class="w-[256px]"
|
||||
placeholder="选择一个国家"
|
||||
selection-mode="single"
|
||||
>
|
||||
<Label>国家</Label>
|
||||
<AutocompleteTrigger>
|
||||
<AutocompleteValue />
|
||||
<AutocompleteClearButton />
|
||||
<AutocompleteIndicator />
|
||||
</AutocompleteTrigger>
|
||||
<AutocompletePopover>
|
||||
<AutocompleteFilter>
|
||||
<SearchField aria-label="搜索国家">
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldSearchIcon />
|
||||
<SearchFieldInput placeholder="搜索国家…" />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox>
|
||||
<ListBoxSection>
|
||||
<Header>北美洲</Header>
|
||||
<ListBoxItem id="usa" text-value="美国">
|
||||
美国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="canada" text-value="加拿大">
|
||||
加拿大
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="mexico" text-value="墨西哥">
|
||||
墨西哥
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBoxSection>
|
||||
<Separator />
|
||||
<ListBoxSection>
|
||||
<Header>欧洲</Header>
|
||||
<ListBoxItem id="uk" text-value="英国">
|
||||
英国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="france" text-value="法国">
|
||||
法国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="germany" text-value="德国">
|
||||
德国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="spain" text-value="西班牙">
|
||||
西班牙
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="italy" text-value="意大利">
|
||||
意大利
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBoxSection>
|
||||
<Separator />
|
||||
<ListBoxSection>
|
||||
<Header>亚洲</Header>
|
||||
<ListBoxItem id="japan" text-value="日本">
|
||||
日本
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="china" text-value="中国">
|
||||
中国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="india" text-value="印度">
|
||||
印度
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="south-korea" text-value="韩国">
|
||||
韩国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBoxSection>
|
||||
<template #empty>
|
||||
<EmptyState class="p-1">未找到结果</EmptyState>
|
||||
</template>
|
||||
</ListBox>
|
||||
</AutocompleteFilter>
|
||||
</AutocompletePopover>
|
||||
</Autocomplete>
|
||||
</template>
|
||||
Reference in New Issue
Block a user