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
@@ -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>