fix: align Dropdown/Menu with the HeroUI baseline after fidelity audit

- menu-item.css keys disabled styling off the presence attribute Reka emits.
- Dropdown surfaces drive the ported enter/exit animations and use data-side
  for placement-specific motion.
- One role=menu per popup; items render their key as DOM id; submenu surfaces
  point aria-labelledby at the real trigger; MenuSection names its group from a
  nested Header.
- Custom (asChild) triggers stay keyboard focusable; library Button/Avatar keep
  their own layout instead of the custom-trigger rules.
- Items emit data-focused/data-hovered/data-pressed, expose the upstream render
  props to slots, and merge caller classes through tailwind-variants.
- Submenu triggers declare hasSubmenu explicitly and forward class/ARIA; the
  default submenu indicator uses the baseline chevron artwork.
- Demos restore Kbd slot="keyboard" (27x), IconSquarePlus, and remove the added
  comment, stray space and duplicated indicator SVGs.
- Document the page after the official structure and API tables, including
  renamed props, Vue extensions and remaining gaps.
This commit is contained in:
maoyingjie
2026-10-24 22:14:10 +08:00
parent 64aaf5e53f
commit 043a5418f3
27 changed files with 1124 additions and 254 deletions
+226 -76
View File
@@ -5,7 +5,7 @@ component: dropdown
group: 组件
---
> 基于固定 HeroUI 3.2.6(ce90ea3)迁移。命名组件、作用域插槽与 DOM attrs 为 Vue 适配;预览、复制与高亮来自同一份 SFC。
> 基于固定 HeroUI 3.2.6(`ce90ea3`)迁移:React 对象部件改为具名导出,`Selection`/`Set` 改为 `MenuKey[]`,回调改为 Vue 事件;预览、复制与高亮来自同一份 SFC。
## 用法
@@ -13,11 +13,12 @@ group: 组件
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Label,
Button,
Label,
} from "@heroui-vue/components";
</script>
```
@@ -27,16 +28,59 @@ import {
## 组件结构
```vue
<DropdownRoot>
<Button variant="secondary" aria-label="菜单">操作</Button>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="new-file" text-value="新建文件">
<Label>新建文件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
<script setup lang="ts">
import {
Button,
Description,
DropdownItem,
DropdownItemIndicator,
DropdownMenu,
DropdownPopover,
DropdownRoot,
DropdownSection,
DropdownSubmenuIndicator,
DropdownSubmenuTrigger,
DropdownTrigger,
Header,
Kbd,
Label,
Separator,
} from "@heroui-vue/components";
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button />
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu>
<DropdownItem>
<Label />
<Description />
<Kbd slot="keyboard" />
<DropdownItemIndicator />
</DropdownItem>
<Separator />
<DropdownSection>
<Header />
<DropdownItem />
</DropdownSection>
<DropdownSubmenuTrigger>
<DropdownItem>
<Label />
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem />
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
```
## 示例
@@ -109,15 +153,24 @@ import {
### 全局 CSS
若要自定义组件类,可使用 `@layer components` 指令。
可使用 `@layer components` 指令自定义 Dropdown 组件类。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
```css
@layer components {
.hv-dropdown {
@apply flex flex-col gap-1;
}
.hv-dropdown__trigger {
@apply outline-none;
}
.hv-dropdown__popover {
@apply rounded-2xl bg-overlay shadow-lg;
@apply rounded-3xl border border-border bg-overlay p-2;
}
.hv-dropdown__menu {
@apply flex flex-col gap-1;
}
}
```
@@ -128,91 +181,146 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
### CSS 类
Dropdown 组件使用以下 CSS 类(类名统一加 `hv-` 前缀):
#### 基础类
- `.hv-dropdown` — 根容器
- `.hv-dropdown__trigger` — 触发器
- `.hv-dropdown__popover` — 浮层
- `.hv-dropdown__menu` — 菜单容器
- `.hv-dropdown` — Dropdown 根容器(Vue 端渲染的包裹元素)
- `.hv-dropdown__trigger` — 触发 Dropdown 的按钮或元素
- `.hv-dropdown__popover` — Popover 容器
- `.hv-dropdown__menu` — Popover 内的菜单容器
#### 菜单组件类
#### 状态类
- `.hv-menu` — 菜单列表
- `.hv-menu-item` — 菜单项
- `.hv-menu-item__indicator` — 选中指示器
- `.hv-menu-item__indicator--submenu` — 子菜单指示器
- `.hv-menu-item--default` / `.hv-menu-item--danger` — 变体
- `.hv-menu-section` — 分组
- `.hv-dropdown__trigger[data-focus-visible="true"]` — 触发器聚焦状态
- `.hv-dropdown__trigger[data-disabled="true"]` — 触发器禁用状态
- `.hv-dropdown__trigger[data-pressed="true"]` — 触发器按下状态
- `.hv-dropdown__popover[data-entering="true"]` — 进入动画状态
- `.hv-dropdown__popover[data-exiting="true"]` — 退出动画状态
- `.hv-dropdown__popover[data-side="top|bottom|left|right"]` — 定位方向(进入动画的位移方向)
- `.hv-dropdown__menu[data-selection-mode="single"]` — 单选模式
- `.hv-dropdown__menu[data-selection-mode="multiple"]` — 多选模式
### 菜单组件类
Dropdown 使用 Menu、MenuItem 与 MenuSection 作为底层组件。以下类名也可用于自定义:
#### 菜单类
- `.hv-menu` — 菜单容器
- `[data-slot="separator"]` — 菜单内的分隔线元素
#### 菜单项类
- `.hv-menu-item` — 菜单项容器
- `.hv-menu-item__indicator` — 选中指示器(对勾或圆点)
- `[data-slot="menu-item-indicator--checkmark"]` — 对勾指示器 SVG
- `[data-slot="menu-item-indicator--dot"]` — 圆点指示器 SVG
- `.hv-menu-item__indicator--submenu` — 子菜单指示器(箭头)
- `.hv-menu-item--default` — 默认样式变体
- `.hv-menu-item--danger` — 危险样式变体
#### 菜单项状态类
- `.hv-menu-item[data-focus-visible="true"]` — 聚焦状态(键盘焦点)
- `.hv-menu-item[data-focused]` — 聚焦状态
- `.hv-menu-item[data-pressed]` — 按下状态
- `.hv-menu-item[data-hovered]` — 悬停状态
- `.hv-menu-item[data-selected="true"]` — 选中状态
- `.hv-menu-item[data-disabled]` — 禁用状态(存在即禁用)
- `.hv-menu-item[data-has-submenu="true"]` — 带子菜单的项
- `.hv-menu-item[data-selection-mode="single"]` — 单选模式
- `.hv-menu-item[data-selection-mode="multiple"]` — 多选模式
- `.hv-menu-item[aria-checked="true"]` — 已勾选(ARIA)
#### 菜单分区类
- `.hv-menu-section` — 菜单分区容器
### 交互状态
- **悬停**:`:hover` 或 `[data-hovered="true"]`
- **聚焦**:`:focus-visible` 或 `[data-focus-visible="true"]`
- **按下**:`[data-pressed="true"]`
- **选中**:`[aria-checked="true"]` / `[data-selected="true"]`
- **禁用**:`[data-disabled="true"]`
- **进入/退出**:`[data-entering]` / `[data-exiting]`
- **放置**:`[data-placement="*"]`
组件同时支持 CSS 伪类与 data 属性:
- **Hover**:触发器与菜单项上 `:hover` 或 `[data-hovered]`
- **Focus**:触发器与菜单项上 `:focus-visible` 或 `[data-focus-visible="true"]`;菜单项另有 `[data-focused]`
- **Disabled**:触发器上 `:disabled`/`[aria-disabled="true"]`,菜单项上 `[data-disabled]`
- **Pressed**:菜单项与触发器上 `:active` 或 `[data-pressed]`
- **Selected**:菜单项上 `[data-selected="true"]` 或 `[aria-checked="true"]`
- **Open/Close**:`DropdownPopover` 上 `[data-state="open"]`;进入/退出期间另有 `[data-entering="true"]` / `[data-exiting="true"]`
## API 参考
所有部件接受 `class`、`style`、ARIA 与原生事件。选择集合使用 Vue 数组模型(`MenuKey[]`),不使用 React `Set`/`Selection`。
所有部件接受 `class`、`style`、ARIA 与原生事件(`DropdownSubmenuTrigger` 会把它们合并到它的条目元素上)。选择集合使用 Vue 数组模型(`MenuKey[]`),不使用 React `Set`/`Selection`。标记「Vue 扩展」的属性在官方 HeroUI 中没有对应项。
### DropdownRoot
| Prop | 类型 | 默认值 | 描述 |
| ------------------- | ------------------------ | --------- | ------------------------------- |
| `open` | `boolean` | — | 受控展开 |
| `defaultOpen` | `boolean` | — | 非受控初始展开 |
| `modal` | `boolean` | `true` | 模态焦点管理 |
| `dir` | `'ltr' \| 'rtl'` | — | 文本方向 |
| `trigger` | `'press' \| 'longPress'` | `'press'` | 长按打开并抑制随后 click |
| `longPressDuration` | `number` | `500` | 长按时长 ms;移动超过 10px 取消 |
| `update:open` | 事件 | — | 展开变更 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------- | ------------------------ | --------- | --------------------------------------------- |
| `open` | `boolean` | — | 设置菜单展开状态(受控)。官方名 `isOpen` |
| `defaultOpen` | `boolean` | — | 设置菜单默认展开状态(非受控)。 |
| `trigger` | `'press' \| 'longPress'` | `'press'` | 触发菜单的交互类型。 |
| `update:open` | 事件 `(open: boolean)` | — | 展开状态变化时触发。官方名 `onOpenChange` |
| `modal` | `boolean` | `true` | **Vue 扩展**:模态焦点管理 |
| `dir` | `'ltr' \| 'rtl'` | — | **Vue 扩展**:文本方向 |
| `longPressDuration` | `number` | `500` | **Vue 扩展**:长按时长 ms;移动超过 10px 取消 |
长按模式下 Enter/Space 仍可键盘打开;`pointerup`/`pointercancel`/`pointerleave`/卸载会清理计时。
### DropdownTrigger
| Prop | 类型 | 默认值 | 描述 |
| --------- | --------- | ------ | ---------------------- |
| `asChild` | `boolean` | `true` | 将触发合并到唯一子节点 |
| Prop | 类型 | 默认值 | 描述 |
| --------- | --------- | ------ | ---------------------------------- |
| `asChild` | `boolean` | `true` | 将触发合并到唯一子节点(默认行为) |
| `as` | `string` | — | 自定义触发元素标签 |
页面里的 `Button` props 写在内部的 `Button` 上。子节点若不是原生可聚焦元素(例如 Avatar),组件会补 `role="button"` 与 `tabindex="0"`,保持官方「触发器可键盘操作」的行为。
### DropdownPopover
| Prop | 类型 | 默认值 | 描述 |
| ----------------- | --------- | ------ | ---------------- |
| `side` / `align` | `string` | — | 相对触发器的位置 |
| `sideOffset` | `number` | — | 侧边偏移 |
| `avoidCollisions` | `boolean` | — | 碰撞翻转 |
| `loop` | `boolean` | — | 焦点循环 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------ | --------- | ------ | ------------------------------------- |
| `side` / `align` | `string` | — | 相对触发器的位置。官方用 `placement` |
| `sideOffset` | `number` | — | 侧边偏移。官方名 `offset` |
| `alignOffset` | `number` | — | 交叉轴偏移。官方名 `crossOffset` |
| `avoidCollisions` | `boolean` | — | 碰撞翻转。官方名 `shouldFlip` |
| `collisionPadding` | `number` | — | 边界内边距。官方名 `containerPadding` |
| `loop` | `boolean` | — | **Vue 扩展**:焦点循环 |
### DropdownMenu
| Prop | 类型 | 默认值 | 描述 |
| ----------------------------------------- | ---------------------------------- | -------- | ----------- |
| `selectionMode` | `'none' \| 'single' \| 'multiple'` | `'none'` | 选择模式 |
| `selectedKeys` / `defaultSelectedKeys` | `MenuKey[]` | — / `[]` | 受控 / 初始 |
| `disabledKeys` | `MenuKey[]` | `[]` | 禁用项 |
| `update:selectedKeys` / `selectionChange` | 事件 | — | 选择变更 |
| `action` | 事件 `(key: MenuKey)` | — | 动作项激活 |
| Prop | 类型 | 默认值 | 描述 |
| ----------------------------------------- | ---------------------------------- | -------- | ------------------------------------------ |
| `selectionMode` | `'none' \| 'single' \| 'multiple'` | `'none'` | 是否启用单选、多选或不启用选择。 |
| `selectedKeys` | `MenuKey[]` | — | 当前选中的 key(受控)。 |
| `defaultSelectedKeys` | `MenuKey[]` | `[]` | 初始选中的 key(非受控)。 |
| `disabledKeys` | `MenuKey[]` | `[]` | 禁用项的 key。 |
| `update:selectedKeys` / `selectionChange` | 事件 `(keys: MenuKey[])` | — | 选中变化时触发。官方名 `onSelectionChange` |
| `action` | 事件 `(key: MenuKey)` | — | 激活菜单项时触发。官方名 `onAction` |
### DropdownSection
与 `DropdownMenu` 相同的选择 Props,可在分组内独立拥有 `selectionMode` / `selectedKeys`。
| Prop | 类型 | 默认值 | 描述 |
| ----------------------------------------- | ------------------------ | ------ | ------------------------------------------ |
| `selectionMode` | `'single' \| 'multiple'` | — | 该分组内菜单项的选择模式;省略则继承菜单。 |
| `selectedKeys` | `MenuKey[]` | — | 当前选中的 key(受控)。 |
| `defaultSelectedKeys` | `MenuKey[]` | `[]` | 初始选中的 key(非受控)。 |
| `disabledKeys` | `MenuKey[]` | `[]` | 禁用项的 key。 |
| `update:selectedKeys` / `selectionChange` | 事件 `(keys: MenuKey[])` | — | 选中变化时触发。官方名 `onSelectionChange` |
分组内嵌套的 `Header` 会自动成为分组的可访问名称来源(`aria-labelledby`)。
### DropdownItem
| Prop | 类型 | 默认值 | 描述 |
| --------------- | ----------------------- | ----------- | ---------------------------- |
| `id` | `MenuKey` | — | 条目标识 |
| `textValue` | `string` | — | 首字母导航文本 |
| `variant` | `'default' \| 'danger'` | `'default'` | 视觉变体 |
| `isDisabled` | `boolean` | `false` | 禁用 |
| `closeOnSelect` | `boolean` | — | `false` 时动作后保持菜单打开 |
| `select` | 事件 `(key: MenuKey)` | — | 激活回调 |
| Prop | 类型 | 默认值 | 描述 |
| --------------- | ----------------------- | ----------- | ---------------------------------------------------------------- |
| `id` | `MenuKey` | — | 菜单项唯一标识,同时作为元素 `id`。 |
| `textValue` | `string` | — | 用于首字母导航的文本内容。 |
| `variant` | `'default' \| 'danger'` | `'default'` | 菜单项视觉变体。 |
| `isDisabled` | `boolean` | `false` | 禁用该项。 |
| `closeOnSelect` | `boolean` | — | `false` 时动作项激活后保持菜单打开。官方名 `shouldCloseOnSelect` |
| `select` | 事件 `(key: MenuKey)` | — | **Vue 扩展**:条目激活回调 |
**事件取消**:条目上 `@click.prevent`(或 `preventDefault`)会取消默认动作、选择变更与关闭。选择项输出 `menuitemradio`/`menuitemcheckbox` 并带 `aria-checked`;`selectionMode=none` 为 `menuitem`。
默认插槽会收到 `{ isSelected, isFocused, isDisabled, isPressed }`,对应官方的 Render Props。
### DropdownItemIndicator
@@ -220,24 +328,66 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
| ------ | ---------------------- | ------------- | ---------- |
| `type` | `'checkmark' \| 'dot'` | `'checkmark'` | 指示器类型 |
### DropdownSubmenuIndicator / DropdownSubmenuTrigger
默认插槽会收到 `{ isSelected, isIndeterminate, isFocused, isDisabled, isPressed }`(菜单项没有不确定态,`isIndeterminate` 恒为 `false`):
子菜单指示器默认 chevron-right;`DropdownSubmenuTrigger` 包裹条目与嵌套 `DropdownPopover`,每层子菜单独立 open 状态。
```vue
<DropdownItemIndicator v-slot="{ isSelected }">
<MyCheckIcon v-if="isSelected" />
</DropdownItemIndicator>
```
### DropdownSubmenuIndicator
| 内容 | 说明 |
| ---- | ---------------------------------------- |
| 默认 | 官方内置的 chevron-right 图标 |
| 插槽 | 自定义指示器内容;只有带子菜单的项才渲染 |
### DropdownSubmenuTrigger
| Slots / Props | 说明 |
| ------------- | -------------------------------------------------- |
| 默认插槽 | 第一个子节点是触发条目,其余子节点渲染进子菜单内容 |
| `class`/ARIA | 合并到触发条目元素上 |
每层子菜单独立持有 open 状态;焦点在子菜单内按 Esc 只关闭当前层,焦点回到该层触发器。
### Render Props
在 `DropdownItem` 中使用作用域插槽时,会收到以下值:
| Prop | 类型 | 描述 |
| ------------ | --------- | ---------------------- |
| `isSelected` | `boolean` | 该项是否选中。 |
| `isFocused` | `boolean` | 该项是否聚焦。 |
| `isDisabled` | `boolean` | 该项是否禁用。 |
| `isPressed` | `boolean` | 该项是否处于按下状态。 |
## 无障碍
菜单使用 `role="menu"` / `menuitem`。上下键与首尾导航、Enter/Space 激活、Esc 关闭并恢复触发器焦点。禁用项跳过;隐藏/退出条目不进入 Tab 顺序。
Dropdown 组件实现 ARIA 菜单模式,并提供:
- 完整键盘导航(方向键、Home/End、首字母导航)
- 屏幕阅读器对操作与选中变化的播报
- 合理的焦点管理(关闭后焦点回到触发器)
- 禁用态支持
- 长按交互支持
- 子菜单导航,Esc 逐层关闭
菜单使用 `role="menu"` / `menuitem`(选择项为 `menuitemradio` / `menuitemcheckbox`);禁用项跳过,不进入 Tab 顺序。
## 上游差异
- React 对象部件改具名导出;`Selection`/`Set` 改 `MenuKey[]`;`onAction`/`onSelectionChange` 改 Vue 事件。
- 条目 `onClick` `preventDefault` 取消动作/选择/关闭(对应上游可取消事件契约)。
- 长按封装在 `DropdownRoot` `trigger="longPress"`;Menu/Item/Section 导出含 `*Props` 类型。
- `Kbd slot="keyboard"` 为上游原生 slot 透传;本库 Kbd 支持同结构。
- 部件导出为具名组件(`DropdownRoot` / `DropdownTrigger` / …),触发器需要显式包裹,官方是把 `Button` 直接放在 `Dropdown` 下。
- `Selection`/`Set` 改为 `MenuKey[]`;`onAction`/`onSelectionChange` 改为 Vue 事件;`isOpen`/`onOpenChange` 改为 `open` + `v-model:open`。
- `placement` 改为 `side`/`align`(Reka 定位模型),`offset`/`crossOffset`/`shouldFlip`/`containerPadding` 分别改为 `sideOffset`/`alignOffset`/`avoidCollisions`/`collisionPadding`。
- 官方支持的链接型菜单项(`href`/`target`)未实现:底层 Reka 菜单项没有锚点路径。
- 子菜单悬停展开延迟由底层固定为 100ms,未暴露官方 `delay`(默认 200ms)。
- `DropdownRoot` 额外渲染一层 `.hv-dropdown` 包裹元素(官方该类没有 DOM 宿主),用于承载根级 class 与方向。
- 条目 `onClick` 中 `preventDefault()` 会取消动作、选择与关闭;`stopImmediatePropagation()` 会终止后续处理器,均为原生事件语义。
## 相关组件
- [Button 按钮](./button)
- [Popover 弹出层](./popover)
- [ListBox 列表框](./list-box)
- [Separator 分隔线](./separator)
@@ -11,7 +11,6 @@ import {
</script>
<template>
<!-- trigger="longPress": press-and-hold opens; click is suppressed. -->
<DropdownRoot trigger="longPress">
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">长按</Button>
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref } from "vue";
import { defineComponent, h, ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
@@ -15,6 +15,30 @@ import {
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["apple"]);
// 官方示例用一个自定义图标常量复用给每个条目;Vue 端用同名组件保持单一来源。
const CustomCheckmarkIcon = defineComponent({
name: "CustomCheckmarkIcon",
setup: () => () =>
h(
"svg",
{
height: "16",
viewBox: "0 0 16 16",
width: "16",
xmlns: "http://www.w3.org/2000/svg",
},
[
h("path", {
class: "text-accent",
"clip-rule": "evenodd",
d: "M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z",
fill: "currentColor",
"fill-rule": "evenodd",
}),
],
),
});
</script>
<template>
<DropdownRoot>
@@ -31,102 +55,32 @@ const selected = ref<MenuKey[]>(["apple"]);
<Header>选择水果</Header>
<DropdownItem id="apple" text-value="苹果">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>梨</Label>
</DropdownItem>
@@ -2,7 +2,7 @@
import {
IconDeviceFloppy,
IconFolderOpen,
IconPlus,
IconSquarePlus,
IconTrash,
} from "@tabler/icons-vue";
import {
@@ -32,13 +32,13 @@ function onAction(key: string | number) {
<DropdownMenu @action="onAction">
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
<IconSquarePlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
@@ -51,7 +51,7 @@ function onAction(key: string | number) {
<Label>打开文件</Label>
<Description>打开已有文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
@@ -64,7 +64,7 @@ function onAction(key: string | number) {
<Label>保存文件</Label>
<Description>保存当前文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
@@ -77,7 +77,7 @@ function onAction(key: string | number) {
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
@@ -1,5 +1,10 @@
<script setup lang="ts">
import { IconMenu2, IconPencil, IconPlus, IconTrash } from "@tabler/icons-vue";
import {
IconMenu2,
IconPencil,
IconSquarePlus,
IconTrash,
} from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
@@ -34,13 +39,13 @@ function onAction(key: string | number) {
<Header>操作</Header>
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
<IconSquarePlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
@@ -53,7 +58,7 @@ function onAction(key: string | number) {
<Label>编辑文件</Label>
<Description>进行修改</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>E</KbdContent>
</Kbd>
@@ -70,7 +75,7 @@ function onAction(key: string | number) {
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
+6 -6
View File
@@ -2,7 +2,7 @@
import {
IconDeviceFloppy,
IconFolderOpen,
IconPlus,
IconSquarePlus,
IconTrash,
} from "@tabler/icons-vue";
import {
@@ -30,9 +30,9 @@ function onAction(key: string | number) {
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new-file" text-value="新建文件">
<IconPlus class="size-4 shrink-0 text-muted" />
<IconSquarePlus class="size-4 shrink-0 text-muted" />
<Label>新建文件</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
@@ -40,7 +40,7 @@ function onAction(key: string | number) {
<DropdownItem id="open-file" text-value="打开文件">
<IconFolderOpen class="size-4 shrink-0 text-muted" />
<Label>打开文件</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
@@ -48,7 +48,7 @@ function onAction(key: string | number) {
<DropdownItem id="save-file" text-value="保存文件">
<IconDeviceFloppy class="size-4 shrink-0 text-muted" />
<Label>保存文件</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
@@ -56,7 +56,7 @@ function onAction(key: string | number) {
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<IconTrash class="size-4 shrink-0 text-danger" />
<Label>删除文件</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
@@ -25,28 +25,28 @@ function onAction(key: string | number) {
<DropdownMenu @action="onAction">
<DropdownItem id="new" text-value="新建">
<Label>新建</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="open" text-value="打开">
<Label>打开</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="save" text-value="保存">
<Label>保存</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="delete" text-value="删除" variant="danger">
<Label>删除</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
@@ -32,21 +32,21 @@ const textAlignment = ref<MenuKey[]>(["left"]);
<Header>操作</Header>
<DropdownItem id="cut" text-value="剪切">
<Label>剪切</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>X</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="copy" text-value="复制">
<Label>复制</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>C</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="paste" text-value="粘贴">
<Label>粘贴</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>U</KbdContent>
</Kbd>
@@ -62,7 +62,7 @@ const textAlignment = ref<MenuKey[]>(["left"]);
<DropdownItem id="bold" text-value="粗体">
<DropdownItemIndicator />
<Label>粗体</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>B</KbdContent>
</Kbd>
@@ -70,7 +70,7 @@ const textAlignment = ref<MenuKey[]>(["left"]);
<DropdownItem id="italic" text-value="斜体">
<DropdownItemIndicator />
<Label>斜体</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>I</KbdContent>
</Kbd>
@@ -78,7 +78,7 @@ const textAlignment = ref<MenuKey[]>(["left"]);
<DropdownItem id="underline" text-value="下划线">
<DropdownItemIndicator />
<Label>下划线</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>U</KbdContent>
</Kbd>
@@ -94,7 +94,7 @@ const textAlignment = ref<MenuKey[]>(["left"]);
<DropdownItem id="left" text-value="左对齐">
<DropdownItemIndicator type="dot" />
<Label>左对齐</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>A</KbdContent>
</Kbd>
@@ -102,7 +102,7 @@ const textAlignment = ref<MenuKey[]>(["left"]);
<DropdownItem id="center" text-value="居中">
<DropdownItemIndicator type="dot" />
<Label>居中</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>H</KbdContent>
</Kbd>
@@ -110,7 +110,7 @@ const textAlignment = ref<MenuKey[]>(["left"]);
<DropdownItem id="right" text-value="右对齐">
<DropdownItemIndicator type="dot" />
<Label>右对齐</Label>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>D</KbdContent>
</Kbd>
+5 -5
View File
@@ -2,7 +2,7 @@
import {
IconDotsVertical,
IconPencil,
IconPlus,
IconSquarePlus,
IconTrash,
} from "@tabler/icons-vue";
import {
@@ -39,13 +39,13 @@ function onAction(key: string | number) {
<Header>操作</Header>
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
<IconSquarePlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
@@ -58,7 +58,7 @@ function onAction(key: string | number) {
<Label>编辑文件</Label>
<Description>进行修改</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>E</KbdContent>
</Kbd>
@@ -75,7 +75,7 @@ function onAction(key: string | number) {
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" slot="keyboard" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>