Merge Select migration and browser verification
# Conflicts: # AGENTS.md # docs/migration-handoff.md # docs/upstream.md # docs/verification.md # package.json # packages/styles/src/index.ts # packages/vue/src/index.ts # packages/vue/src/types.ts # tests/package/README.md
This commit is contained in:
@@ -103,6 +103,7 @@ const groups = [
|
||||
{ title: "NumberField 数字输入框", url: "/components/number-field" },
|
||||
{ title: "Slider 滑块", url: "/components/slider" },
|
||||
{ title: "ListBox 列表框", url: "/components/list-box" },
|
||||
{ title: "Select 选择器", url: "/components/select" },
|
||||
{ title: "Tooltip 工具提示", url: "/components/tooltip" },
|
||||
{
|
||||
title: "ToggleButton 切换按钮",
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
---
|
||||
title: Select 选择器
|
||||
description: Select 展示可折叠的选项列表,并允许用户从中选择一项。
|
||||
component: select
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="select-default" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectClearButton,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
Label,
|
||||
Description,
|
||||
Header,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
ListBoxSection,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Select>
|
||||
<Label>选项</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectClearButton />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<Description>请选择一项</Description>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="first" text-value="第一项">
|
||||
<div>
|
||||
<Label>第一项</Label>
|
||||
<Description>选项说明</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxSection>
|
||||
<Header>分组</Header>
|
||||
<ListBoxItem id="second" text-value="第二项">
|
||||
<Label>第二项</Label>
|
||||
</ListBoxItem>
|
||||
</ListBoxSection>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
Select 组件支持两种视觉变体:
|
||||
|
||||
- **`primary`**(默认)— 带阴影的标准样式,适用于大多数场景
|
||||
- **`secondary`** — 低强调、无阴影,适合在 Surface 等表面背景上使用
|
||||
|
||||
<ComponentPreview name="select-variants" />
|
||||
|
||||
### 宽度充满
|
||||
|
||||
<ComponentPreview name="select-full-width" />
|
||||
|
||||
### 带描述
|
||||
|
||||
<ComponentPreview name="select-with-description" />
|
||||
|
||||
### 必填
|
||||
|
||||
<ComponentPreview name="select-required" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="select-disabled" />
|
||||
|
||||
### 含禁用选项
|
||||
|
||||
<ComponentPreview name="select-with-disabled-options" />
|
||||
|
||||
### 多选
|
||||
|
||||
<ComponentPreview name="select-multiple-select" />
|
||||
|
||||
### 分组选项
|
||||
|
||||
<ComponentPreview name="select-with-sections" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
<ComponentPreview name="select-controlled" />
|
||||
|
||||
### 受控多选
|
||||
|
||||
<ComponentPreview name="select-controlled-multiple" />
|
||||
|
||||
### 受控展开状态
|
||||
|
||||
<ComponentPreview name="select-controlled-open-state" />
|
||||
|
||||
### 异步加载
|
||||
|
||||
Vue 使用响应式数组、Fetch 与 VueUse 可见性观察加载 PokeAPI 分页;保留取消、加载中、错误重试和手动加载入口,不导出 React Collection / ListBoxLoadMoreItem。
|
||||
|
||||
<ComponentPreview name="select-asynchronous-loading" />
|
||||
|
||||
### 自定义指示器
|
||||
|
||||
<ComponentPreview name="select-custom-indicator" />
|
||||
|
||||
### 带清除按钮
|
||||
|
||||
`SelectTrigger` 本身是 button,因此不能再嵌套 `<button>` 来实现清除。请在触发器内组合 `SelectClearButton` — 它渲染为非 button 控件,且不会打开菜单。
|
||||
|
||||
<ComponentPreview name="select-with-clear-button" />
|
||||
|
||||
由于 ARIA 将 button 的子节点视为纯展示内容,清除控件无法获得焦点,因此它带有 `aria-hidden`,仅作为指针操作的可视入口。当组合了 `SelectClearButton` 时,触发器同时支持按 `Backspace` 或 `Delete` 清除,这是键盘与屏幕阅读器用户的清除方式。两种方式都会调用 `clear`。
|
||||
|
||||
### 自定义展示值
|
||||
|
||||
<ComponentPreview name="select-custom-value" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
通过 `as`、原生 attrs 和作用域插槽表达 Vue 渲染能力。
|
||||
|
||||
<ComponentPreview
|
||||
name="select-render-function"
|
||||
/>
|
||||
|
||||
### 表面样式
|
||||
|
||||
在 [Surface](/components/surface) 内使用时,请使用 `variant="secondary"`,以应用适合表面背景的低强调变体。
|
||||
|
||||
<ComponentPreview name="select-on-surface" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="select-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-select {
|
||||
@apply flex flex-col gap-1;
|
||||
}
|
||||
|
||||
.hv-select__trigger {
|
||||
@apply rounded-lg border border-border bg-surface p-2;
|
||||
}
|
||||
|
||||
.hv-select__value {
|
||||
@apply text-current;
|
||||
}
|
||||
|
||||
.hv-select__indicator {
|
||||
@apply text-muted;
|
||||
}
|
||||
|
||||
.hv-select__popover {
|
||||
@apply rounded-lg border border-border bg-surface p-2;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Select 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/select.css)):
|
||||
|
||||
#### 基础类
|
||||
|
||||
- `.hv-select` - Select 根容器
|
||||
- `.hv-select__trigger` - 打开下拉的触发按钮
|
||||
- `.hv-select__value` - 当前显示的值或占位符
|
||||
- `.hv-select__clear-button` - 触发器内的可选清除控件
|
||||
- `.hv-select__indicator` - 下拉指示图标
|
||||
- `.hv-select__popover` - 弹出层容器
|
||||
|
||||
#### 变体类
|
||||
|
||||
- `.hv-select--primary` - Primary 变体,带阴影(默认)
|
||||
- `.hv-select--secondary` - Secondary 变体,无阴影,适合在 Surface 上使用
|
||||
|
||||
#### 状态类
|
||||
|
||||
- `.hv-select[data-invalid="true"]` - 无效状态
|
||||
- `.hv-select__trigger[data-focus-visible="true"]` - 触发器聚焦状态
|
||||
- `.hv-select__trigger[data-disabled="true"]` - 触发器禁用状态
|
||||
- `.hv-select__value[data-placeholder="true"]` - 占位符状态
|
||||
- `.hv-select__clear-button[data-empty="true"]` - 无选中项时隐藏清除控件
|
||||
- `.hv-select__indicator[data-open="true"]` - 展开时的指示器状态
|
||||
|
||||
### 交互状态
|
||||
|
||||
该组件同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制:
|
||||
|
||||
- **悬停**:触发器上的 `:hover` 或 `[data-hovered="true"]`
|
||||
- **聚焦**:触发器上的 `:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **禁用**:Select 上的 `:disabled` 或 `[data-disabled="true"]`
|
||||
- **展开**:指示器上的 `[data-open="true"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
### Select
|
||||
|
||||
`SelectRoot` 是 `Select` 的别名。Key 为字符串或有限数值,数字 `0` 和字符串 `"0"` 不相同,空字符串有效。单选清空为 `null`,多选为 `[]`。显式 `modelValue` 优先于 `value`,显式 `open` 优先于 `isOpen`,包括显式传入 `undefined`。
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------------------ | --------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `placeholder` | `string` | `"Select an item"` | 空选择的占位符。 |
|
||||
| `selectionMode` | `"single" \| "multiple"` | `"single"` | 单选或多选。ListBox 的选择模式由 Select 统一管理。 |
|
||||
| `modelValue` / `value` | `Key \| Key[] \| null` | — | 受控值,推荐 `v-model`。多选必须是数组。 |
|
||||
| `defaultValue` | `Key \| Key[] \| null` | `null` / `[]` | 非受控初值,也是 reset 的目标值。 |
|
||||
| `open` / `isOpen` | `boolean` | — | 受控展开状态,推荐 `v-model:open`。 |
|
||||
| `defaultOpen` | `boolean` | `false` | 非受控展开初值。 |
|
||||
| `disabledKeys` | `readonly Key[]` | — | 禁用选项 key;Vue 使用数组替代 Iterable。 |
|
||||
| `items` | `readonly SelectItem[]` | — | `{ id, textValue, isDisabled? }` 完整元数据。用于不透明包装和异步数据,保证关闭态/SSR 的文字与提交正确;不负责渲染选项。 |
|
||||
| `isDisabled` / `disabled` | `boolean` | `false` | 禁用交互与原生提交;继承 Fieldset 禁用。 |
|
||||
| `isReadOnly` | `boolean` | `false` | 保留提交值,阻止用户改选与展开。 |
|
||||
| `isRequired` | `boolean` | `false` | 必填,校验有效且未禁用的已选项。 |
|
||||
| `isInvalid` | `boolean` | `false` | 外部无效状态。 |
|
||||
| `validationBehavior` | `"native" \| "aria"` | 继承 Form,默认 `"native"` | 原生约束或仅 ARIA 校验。 |
|
||||
| `validate` | `(value: SelectModelValue) => ValidateResult` | — | 本地自定义校验;同时消费 Form 服务端错误。 |
|
||||
| `name` / `form` | `string` | — | 原生表单名称和外部 form ID。多选同名重复提交;空/不存在/禁用选项不提交。 |
|
||||
| `autoComplete` | `string` | — | 传给唯一的原生 select 自动填充层;空选择时用稳定 ID 标识,首次自动填充是否出现由浏览器决定。 |
|
||||
| `fullWidth` | `boolean` | `false` | 占满容器宽度。 |
|
||||
| `variant` | `"primary" \| "secondary"` | `"primary"` | 主要/次要变体。 |
|
||||
| `id` | `string` | 自动生成 | 触发器 DOM ID,关联 Label、选项列表与校验。 |
|
||||
| `as` | `string` | `"div"` | 根 HTML 标签。 |
|
||||
| `class` / `style` / 原生 attrs | 原生属性 | — | 传给根容器。根 `aria-label` 同时用于触发器;触发器可单独覆盖。 |
|
||||
|
||||
### 事件
|
||||
|
||||
| 事件 | 参数 | 描述 |
|
||||
| ------------------------------ | ------------------ | -------------------------------------------------------------------------- |
|
||||
| `update:modelValue` / `change` | `SelectModelValue` | 用户选择提案;父组件未接受时可见状态和 FormData 保持父值,相同提案可重试。 |
|
||||
| `update:open` / `openChange` | `boolean` | 展开状态提案;父更新和 reset 不伪造值变化事件。 |
|
||||
| `clear` | 无 | 指针或关闭态 Backspace/Delete 请求清空;同时触发值事件。 |
|
||||
|
||||
### SelectTrigger
|
||||
|
||||
| Prop / 事件 | 类型 | 默认值 | 描述 |
|
||||
| ------------------------ | --------- | ---------- | ---------------------------------------------------------- |
|
||||
| `as` | `string` | `"button"` | 触发器标签;保留正确键盘激活行为。 |
|
||||
| `isDisabled` | `boolean` | `false` | 单独禁用触发器及其内部清空控件。 |
|
||||
| `class` / `style` / ARIA | 原生属性 | — | 传到真正的交互节点;显式名称优先。 |
|
||||
| 原生键盘/指针事件 | DOM Event | — | 用户处理器先运行,可通过 `preventDefault()` 取消内部行为。 |
|
||||
|
||||
### SelectValue
|
||||
|
||||
| Prop / 插槽 | 类型 | 默认值 | 描述 |
|
||||
| ----------------- | ---------- | -------- | ------------------------ |
|
||||
| `as` | `string` | `"span"` | 展示值标签。 |
|
||||
| `class` / `style` | 原生属性 | — | 值区域样式。 |
|
||||
| `default` | 作用域插槽 | 已选文字 | 自定义展示值,参数如下。 |
|
||||
|
||||
### SelectIndicator
|
||||
|
||||
| Prop / 插槽 | 类型 | 描述 |
|
||||
| ----------------- | ------------- | -------------------------------------------------------------- |
|
||||
| `class` / `style` | 原生属性 | 指示器样式。 |
|
||||
| `default` | 单一 Vue 节点 | 自定义图标;状态与样式合并到该节点。默认使用移植自基线的图标。 |
|
||||
|
||||
### SelectClearButton
|
||||
|
||||
| Prop / 事件 / 插槽 | 类型 | 默认值 | 描述 |
|
||||
| ------------------ | ------------ | ------------ | -------------------------------------- |
|
||||
| `as` | `string` | `"span"` | 保持非 button 标签,避免嵌套交互按钮。 |
|
||||
| `class` / `style` | 原生属性 | — | 清除控件样式。 |
|
||||
| `click` | `MouseEvent` | — | 可取消清除;不会打开弹层。 |
|
||||
| `default` | Vue 插槽 | 基线关闭图标 | 自定义内容。 |
|
||||
|
||||
### SelectPopover
|
||||
|
||||
| Prop / 事件 | 类型 | 默认值 | 描述 |
|
||||
| ----------------------------------- | ----------------------- | ---------- | -------------------------------------------------------------------------------------------------------- |
|
||||
| `placement` | `OverlayPlacement` | `"bottom"` | bottom/top/left/right/start/end 及对应 left/right/top/bottom/start/end 对齐组合,沿用 Popover 定位协议。 |
|
||||
| `offset` | `number` | `8` | 与触发器的距离。 |
|
||||
| `shouldFlip` | `boolean` | `true` | 空间不足时翻转。 |
|
||||
| `containerPadding` | `number` | `12` | 视口碰撞边距。 |
|
||||
| `to` | `string \| HTMLElement` | `body` | Teleport 目标;SSR 默认关闭态不会渲染弹层。 |
|
||||
| `class` / `style` / attrs | 原生属性 | — | 弹层节点属性;选择器只承载一个 ListBox。 |
|
||||
| `openAutoFocus` / `closeAutoFocus` | `Event` | — | 可取消默认焦点。默认进入已选/首项,关闭恢复触发器;外部交互保留外部焦点。 |
|
||||
| `escapeKeyDown` / `interactOutside` | DOM / CustomEvent | — | 复用 Popover 的事件与取消协议。 |
|
||||
|
||||
### 作用域插槽状态
|
||||
|
||||
| 插槽 | 参数 | 描述 |
|
||||
| --------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------- |
|
||||
| Select `default` | `{ value, isOpen, selectedItems }` | 当前接受状态;初次 SSR 需要直接使用 selectedItems 时请提供 items 元数据。 |
|
||||
| SelectValue `default` | `{ defaultChildren, isPlaceholder, selectedItems, state }` | 默认文字、占位状态与选中项。 |
|
||||
| `selectedItems` | `{ key: Key; textValue: string }[]` | 已选元数据;自定义头像等通过业务数据查找。 |
|
||||
| `state` | `{ selectedItems, isOpen }` | Vue 响应式状态快照,不暴露 React SelectState。 |
|
||||
|
||||
非受控 `selectionMode` 切换会适配标量/数组外观,切回单选取首项,不发编辑事件;受控切换应由父组件同时提供匹配模式的值。
|
||||
|
||||
通过组件 ref 调用 `focus()`、`open()`、`close()`,`element` 指向触发器。
|
||||
|
||||
## 无障碍与兼容差异
|
||||
|
||||
- 原生按钮承担触发、取消与禁用。触发器使用选择型 `combobox`,关联实际 `listbox`,选项名称与字段标签隔离。
|
||||
- 方向键进入已选项(空选择时 ArrowDown 首项、ArrowUp 末项),列表复用 ListBox 导航、首字母搜索和禁用跳过。单选激活关闭,多选保持展开;Escape 关闭,Tab 离开弹层。
|
||||
- 复用现有 Popover 非模态焦点与定位体系;与上游 RAC 的移动端原生选择菜单、模态隐藏外部内容不同。当前不提供移动端原生菜单切换。
|
||||
- 关闭态从已知 ListBox/Section/Item 插槽预规划元数据;不执行任意包装组件的 setup/render。不透明包装请提供 Select 的 `items`,否则首次打开前未知选项只能显示 key,且无法提交未知选项。
|
||||
- 唯一原生 select 提交层保留字符串边界,多选使用重复 name;类型区分只用于组件值与事件。浏览器自动填充通过选中 option 的索引恢复原始 key,不把内部编码放进 FormData。
|
||||
- 支持原生必填、重置、Fieldset 与 Form 错误关联;跨浏览器自动填充与实际屏幕阅读器播报仍需专项验收,不声明等同 React Aria 全部能力。
|
||||
- 样式及 19 个中文示例来自固定 HeroUI 基线;React 渲染函数改为 Vue 插槽,文档的表单成功反馈使用内联状态,图标扩展示例使用 Tabler。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[ListBox](/components/list-box)、[Popover](/components/popover)、[Fieldset](/components/fieldset)、[Label](/components/label)、[FieldError](/components/field-error)
|
||||
@@ -0,0 +1,91 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import { useIntersectionObserver } from "@vueuse/core";
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
Spinner,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
const items = ref<{ id: string; textValue: string }[]>([]);
|
||||
const cursor = ref<string | null>("https://pokeapi.co/api/v2/pokemon");
|
||||
const loading = ref(false),
|
||||
error = ref(false),
|
||||
sentinel = ref<HTMLElement>();
|
||||
let controller: AbortController | undefined;
|
||||
async function loadMore() {
|
||||
if (loading.value || !cursor.value) return;
|
||||
controller = new AbortController();
|
||||
loading.value = true;
|
||||
error.value = false;
|
||||
try {
|
||||
const response = await fetch(cursor.value, { signal: controller.signal });
|
||||
if (!response.ok) throw new Error("Unable to load Pokémon");
|
||||
const page = (await response.json()) as {
|
||||
next: string | null;
|
||||
results: { name: string }[];
|
||||
};
|
||||
const seen = new Set(items.value.map((item) => item.id));
|
||||
items.value.push(
|
||||
...page.results
|
||||
.filter((item) => !seen.has(item.name))
|
||||
.map((item) => ({ id: item.name, textValue: item.name })),
|
||||
);
|
||||
cursor.value = page.next;
|
||||
} catch (cause) {
|
||||
if (!controller.signal.aborted) error.value = true;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
useIntersectionObserver(sentinel, ([entry]) => {
|
||||
if (entry?.isIntersecting && !error.value) void loadMore();
|
||||
});
|
||||
onMounted(loadMore);
|
||||
onBeforeUnmount(() => controller?.abort());
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" placeholder="请选择宝可梦" :items="items">
|
||||
<Label>选择宝可梦</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover class="max-h-80">
|
||||
<ListBox :items="items" :aria-busy="loading || undefined">
|
||||
<template #default="{ item }">
|
||||
<ListBoxItem :id="item.id" :text-value="item.textValue">
|
||||
{{ item.textValue }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</template>
|
||||
<template #empty>
|
||||
<p class="px-4 py-2 text-sm text-muted">
|
||||
{{ error ? "加载失败,请重试" : "正在加载…" }}
|
||||
</p>
|
||||
</template>
|
||||
</ListBox>
|
||||
<div
|
||||
v-if="cursor"
|
||||
ref="sentinel"
|
||||
class="flex items-center justify-center gap-2 py-2"
|
||||
role="status"
|
||||
>
|
||||
<template v-if="loading">
|
||||
<Spinner size="sm" />
|
||||
<span class="text-sm text-muted">加载更多…</span>
|
||||
</template>
|
||||
<Button v-else variant="ghost" size="sm" @click="loadMore">
|
||||
{{ error ? "重试" : "加载更多…" }}
|
||||
</Button>
|
||||
</div>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,80 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { ref, computed } from "vue";
|
||||
import type { SelectModelValue } from "@heroui-vue/components";
|
||||
const states = [
|
||||
{ id: "california", name: "加利福尼亚" },
|
||||
{ id: "texas", name: "德克萨斯" },
|
||||
{ id: "florida", name: "佛罗里达" },
|
||||
{ id: "new-york", name: "纽约" },
|
||||
{ id: "illinois", name: "伊利诺伊" },
|
||||
{ id: "pennsylvania", name: "宾夕法尼亚" },
|
||||
];
|
||||
const state = ref<SelectModelValue>(["california", "texas"]);
|
||||
const selected = computed(
|
||||
() =>
|
||||
states
|
||||
.filter((s) =>
|
||||
Array.isArray(state.value)
|
||||
? state.value.includes(s.id)
|
||||
: state.value === s.id,
|
||||
)
|
||||
.map((s) => s.name)
|
||||
.join(", ") || "无",
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="space-y-2">
|
||||
<Select
|
||||
class="w-[256px]"
|
||||
placeholder="请选择州"
|
||||
v-model="state"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>州(受控多选)</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="illinois" text-value="伊利诺伊">
|
||||
伊利诺伊
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="pennsylvania" text-value="宾夕法尼亚">
|
||||
宾夕法尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
<p class="text-sm text-muted">已选:{{ selected }}</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,57 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
import { ref } from "vue";
|
||||
const open = ref(false);
|
||||
</script>
|
||||
<template>
|
||||
<div class="space-y-4">
|
||||
<Select v-model:open="open" class="w-[256px]" placeholder="请选择">
|
||||
<Label>州</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="特拉华">
|
||||
特拉华
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="华盛顿">
|
||||
华盛顿
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
<Button @click="open = !open">{{ open ? "关闭" : "打开" }}选择框</Button>
|
||||
<p class="text-sm text-muted">选择框{{ open ? "已打开" : "已关闭" }}</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,75 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { ref, computed } from "vue";
|
||||
import type { SelectModelValue } from "@heroui-vue/components";
|
||||
const states = [
|
||||
{ id: "california", name: "加利福尼亚" },
|
||||
{ id: "texas", name: "德克萨斯" },
|
||||
{ id: "florida", name: "佛罗里达" },
|
||||
{ id: "new-york", name: "纽约" },
|
||||
{ id: "illinois", name: "伊利诺伊" },
|
||||
{ id: "pennsylvania", name: "宾夕法尼亚" },
|
||||
];
|
||||
const state = ref<SelectModelValue>("california");
|
||||
const selected = computed(
|
||||
() =>
|
||||
states
|
||||
.filter((s) =>
|
||||
Array.isArray(state.value)
|
||||
? state.value.includes(s.id)
|
||||
: state.value === s.id,
|
||||
)
|
||||
.map((s) => s.name)
|
||||
.join(", ") || "无",
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="space-y-2">
|
||||
<Select class="w-[256px]" placeholder="请选择州" v-model="state">
|
||||
<Label>州(受控)</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="illinois" text-value="伊利诺伊">
|
||||
伊利诺伊
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="pennsylvania" text-value="宾夕法尼亚">
|
||||
宾夕法尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
<p class="text-sm text-muted">已选:{{ selected }}</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconSelector } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" placeholder="请选择">
|
||||
<Label>州</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator class="size-3">
|
||||
<IconSelector />
|
||||
</SelectIndicator>
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="特拉华">
|
||||
特拉华
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="华盛顿">
|
||||
华盛顿
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
const itemClass =
|
||||
"rounded-lg data-[focused=true]:bg-accent/10 data-[selected=true]:text-foreground";
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-56" placeholder="选择套餐" variant="secondary">
|
||||
<Label class="font-medium text-foreground">套餐</Label>
|
||||
<SelectTrigger class="rounded-xl bg-default">
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover
|
||||
class="rounded-xl border border-border bg-surface p-1 shadow-lg"
|
||||
>
|
||||
<ListBox>
|
||||
<ListBoxItem :class="itemClass" id="free" text-value="免费">
|
||||
免费
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem :class="itemClass" id="pro" text-value="专业版">
|
||||
专业版
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,107 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { Avatar, AvatarImage, AvatarFallback } 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",
|
||||
},
|
||||
];
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" placeholder="请选择用户">
|
||||
<Label>用户</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue v-slot="{ defaultChildren, isPlaceholder, selectedItems }">
|
||||
<template v-if="isPlaceholder || !selectedItems.length">
|
||||
{{ 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="
|
||||
users.find((u) => u.id === selectedItems[0]?.key)?.avatarUrl ??
|
||||
''
|
||||
"
|
||||
/>
|
||||
<AvatarFallback>
|
||||
{{ users.find((u) => u.id === selectedItems[0]?.key)?.fallback }}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<span>{{ defaultChildren }}</span>
|
||||
</div>
|
||||
</SelectValue>
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
:id="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>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,50 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" placeholder="请选择">
|
||||
<Label>州</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="特拉华">
|
||||
特拉华
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="华盛顿">
|
||||
华盛顿
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,98 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<Select
|
||||
is-disabled
|
||||
class="w-[256px]"
|
||||
default-value="california"
|
||||
placeholder="请选择"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="特拉华">
|
||||
特拉华
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="华盛顿">
|
||||
华盛顿
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
<Select
|
||||
is-disabled
|
||||
class="w-[256px]"
|
||||
:default-value="['argentina', 'japan', 'france']"
|
||||
placeholder="请选择国家"
|
||||
selection-mode="multiple"
|
||||
>
|
||||
<Label>拟访问国家</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="argentina" text-value="阿根廷">
|
||||
阿根廷
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="venezuela" text-value="委内瑞拉">
|
||||
委内瑞拉
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="japan" text-value="日本">
|
||||
日本
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="france" text-value="法国">
|
||||
法国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="italy" text-value="意大利">
|
||||
意大利
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="spain" text-value="西班牙">
|
||||
西班牙
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="w-[400px] space-y-4">
|
||||
<Select full-width placeholder="请选择">
|
||||
<Label>喜爱的动物</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="cat" text-value="猫">
|
||||
猫
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="dog" text-value="狗">
|
||||
狗
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="bird" text-value="鸟">
|
||||
鸟
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,62 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" placeholder="请选择国家" selection-mode="multiple">
|
||||
<Label>拟访问国家</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox selection-mode="multiple">
|
||||
<ListBoxItem id="argentina" text-value="阿根廷">
|
||||
阿根廷
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="venezuela" text-value="委内瑞拉">
|
||||
委内瑞拉
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="japan" text-value="日本">
|
||||
日本
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="france" text-value="法国">
|
||||
法国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="italy" text-value="意大利">
|
||||
意大利
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="spain" text-value="西班牙">
|
||||
西班牙
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="thailand" text-value="泰国">
|
||||
泰国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-zealand" text-value="新西兰">
|
||||
新西兰
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="iceland" text-value="冰岛">
|
||||
冰岛
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,113 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
Form,
|
||||
FieldError,
|
||||
Button,
|
||||
Surface,
|
||||
} from "@heroui-vue/components";
|
||||
import { ref } from "vue";
|
||||
const submitted = ref(false);
|
||||
</script>
|
||||
<template>
|
||||
<Surface class="w-[320px] rounded-3xl p-6">
|
||||
<Form class="flex w-full flex-col gap-4" @submit.prevent="submitted = true">
|
||||
<Select
|
||||
is-required
|
||||
class="w-full"
|
||||
name="state"
|
||||
placeholder="请选择"
|
||||
variant="secondary"
|
||||
>
|
||||
<Label>州</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="特拉华">
|
||||
特拉华
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="华盛顿">
|
||||
华盛顿
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
<FieldError />
|
||||
</Select>
|
||||
<Select
|
||||
is-required
|
||||
class="w-full"
|
||||
name="country"
|
||||
placeholder="请选择国家"
|
||||
variant="secondary"
|
||||
>
|
||||
<Label>国家</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="usa" text-value="美国">
|
||||
美国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="canada" text-value="加拿大">
|
||||
加拿大
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="mexico" text-value="墨西哥">
|
||||
墨西哥
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="uk" text-value="英国">
|
||||
英国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="france" text-value="法国">
|
||||
法国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="germany" text-value="德国">
|
||||
德国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
<FieldError />
|
||||
</Select>
|
||||
<Button type="submit">提交</Button>
|
||||
<p v-if="submitted" role="status" class="text-sm text-success">
|
||||
表单提交成功!
|
||||
</p>
|
||||
</Form>
|
||||
</Surface>
|
||||
</template>
|
||||
@@ -0,0 +1,50 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" placeholder="请选择" as="div" data-custom="foo">
|
||||
<Label>州</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="特拉华">
|
||||
特拉华
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="华盛顿">
|
||||
华盛顿
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,101 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
Form,
|
||||
FieldError,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
import { ref } from "vue";
|
||||
const submitted = ref(false);
|
||||
</script>
|
||||
<template>
|
||||
<Form
|
||||
class="flex w-[256px] flex-col gap-4"
|
||||
@submit.prevent="submitted = true"
|
||||
>
|
||||
<Select is-required class="w-full" name="state" placeholder="请选择">
|
||||
<Label>州</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="特拉华">
|
||||
特拉华
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="华盛顿">
|
||||
华盛顿
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
<FieldError />
|
||||
</Select>
|
||||
<Select is-required class="w-full" name="country" placeholder="请选择国家">
|
||||
<Label>国家</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="usa" text-value="美国">
|
||||
美国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="canada" text-value="加拿大">
|
||||
加拿大
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="mexico" text-value="墨西哥">
|
||||
墨西哥
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="uk" text-value="英国">
|
||||
英国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="france" text-value="法国">
|
||||
法国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="germany" text-value="德国">
|
||||
德国
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
<FieldError />
|
||||
</Select>
|
||||
<Button type="submit">提交</Button>
|
||||
<p v-if="submitted" role="status" class="text-sm text-success">
|
||||
表单提交成功!
|
||||
</p>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<Select class="w-[256px]" placeholder="请选择" variant="primary">
|
||||
<Label>主要变体</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="option1" text-value="选项 1">
|
||||
Option 1
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="option2" text-value="选项 2">
|
||||
Option 2
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
<Select class="w-[256px]" placeholder="请选择" variant="secondary">
|
||||
<Label>次要变体</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="option1" text-value="选项 1">
|
||||
Option 1
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="option2" text-value="选项 2">
|
||||
Option 2
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectClearButton,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" default-value="california" placeholder="Select one">
|
||||
<Label>State</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectClearButton />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="Florida">
|
||||
Florida
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="Delaware">
|
||||
Delaware
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="California">
|
||||
California
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="Texas">
|
||||
Texas
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="New York">
|
||||
New York
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="Washington">
|
||||
Washington
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" placeholder="请选择">
|
||||
<Label>州</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||||
佛罗里达
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="delaware" text-value="特拉华">
|
||||
特拉华
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||||
加利福尼亚
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||||
德克萨斯
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="new-york" text-value="纽约">
|
||||
纽约
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="washington" text-value="华盛顿">
|
||||
华盛顿
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
<Description>请选择居住州</Description>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Select
|
||||
class="w-[256px]"
|
||||
:disabled-keys="['cat', 'kangaroo']"
|
||||
placeholder="请选择动物"
|
||||
>
|
||||
<Label>动物</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem id="dog" text-value="狗">
|
||||
狗
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="cat" text-value="猫">
|
||||
猫
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="bird" text-value="鸟">
|
||||
鸟
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="kangaroo" text-value="袋鼠">
|
||||
袋鼠
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="elephant" text-value="大象">
|
||||
大象
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<ListBoxItem id="tiger" text-value="老虎">
|
||||
老虎
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -0,0 +1,88 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
ListBoxSection,
|
||||
Label,
|
||||
Header,
|
||||
Separator,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Select class="w-[256px]" placeholder="请选择国家">
|
||||
<Label>国家</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<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>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -15,6 +15,7 @@
|
||||
"@heroui-vue/components": "workspace:*",
|
||||
"@heroui-vue/styles": "workspace:*",
|
||||
"@tabler/icons-vue": "^3.49.0",
|
||||
"@vueuse/core": "14.4.0",
|
||||
"reka-ui": "^2.11.0",
|
||||
"vue": "^3.5.44"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user