Files
heroui-vue/apps/docs/demos/dropdown-single-with-custom-indicator.vue
T
maoyingjie 043a5418f3 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.
2026-10-24 22:14:10 +08:00

91 lines
2.9 KiB
Vue

<script setup lang="ts">
import { defineComponent, h, ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
} from "@heroui-vue/components";
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>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">水果</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu
:selected-keys="selected"
selection-mode="single"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownSection>
<Header>选择水果</Header>
<DropdownItem id="apple" text-value="苹果">
<DropdownItemIndicator v-slot="{ isSelected }">
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator v-slot="{ isSelected }">
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator v-slot="{ isSelected }">
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator v-slot="{ isSelected }">
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator v-slot="{ isSelected }">
<CustomCheckmarkIcon v-if="isSelected" />
</DropdownItemIndicator>
<Label>梨</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>