043a5418f3
- 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.
123 lines
4.1 KiB
Vue
123 lines
4.1 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from "vue";
|
|
import {
|
|
DropdownRoot,
|
|
DropdownTrigger,
|
|
DropdownPopover,
|
|
DropdownMenu,
|
|
DropdownItem,
|
|
DropdownItemIndicator,
|
|
DropdownSection,
|
|
Button,
|
|
Header,
|
|
Label,
|
|
Kbd,
|
|
KbdAbbr,
|
|
KbdContent,
|
|
Separator,
|
|
} from "@heroui-vue/components";
|
|
import type { MenuKey } from "@heroui-vue/components";
|
|
|
|
const textStyles = ref<MenuKey[]>(["bold", "italic"]);
|
|
const textAlignment = ref<MenuKey[]>(["left"]);
|
|
</script>
|
|
<template>
|
|
<DropdownRoot>
|
|
<DropdownTrigger>
|
|
<Button aria-label="菜单" variant="secondary">样式</Button>
|
|
</DropdownTrigger>
|
|
<DropdownPopover class="min-w-[256px]">
|
|
<DropdownMenu>
|
|
<DropdownSection>
|
|
<Header>操作</Header>
|
|
<DropdownItem id="cut" text-value="剪切">
|
|
<Label>剪切</Label>
|
|
<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" slot="keyboard" variant="light">
|
|
<KbdAbbr key-value="command" />
|
|
<KbdContent>C</KbdContent>
|
|
</Kbd>
|
|
</DropdownItem>
|
|
<DropdownItem id="paste" text-value="粘贴">
|
|
<Label>粘贴</Label>
|
|
<Kbd class="ms-auto" slot="keyboard" variant="light">
|
|
<KbdAbbr key-value="command" />
|
|
<KbdContent>U</KbdContent>
|
|
</Kbd>
|
|
</DropdownItem>
|
|
</DropdownSection>
|
|
<Separator />
|
|
<DropdownSection
|
|
:selected-keys="textStyles"
|
|
selection-mode="multiple"
|
|
@update:selected-keys="(keys: MenuKey[]) => (textStyles = keys)"
|
|
>
|
|
<Header>文本样式</Header>
|
|
<DropdownItem id="bold" text-value="粗体">
|
|
<DropdownItemIndicator />
|
|
<Label>粗体</Label>
|
|
<Kbd class="ms-auto" slot="keyboard" variant="light">
|
|
<KbdAbbr key-value="command" />
|
|
<KbdContent>B</KbdContent>
|
|
</Kbd>
|
|
</DropdownItem>
|
|
<DropdownItem id="italic" text-value="斜体">
|
|
<DropdownItemIndicator />
|
|
<Label>斜体</Label>
|
|
<Kbd class="ms-auto" slot="keyboard" variant="light">
|
|
<KbdAbbr key-value="command" />
|
|
<KbdContent>I</KbdContent>
|
|
</Kbd>
|
|
</DropdownItem>
|
|
<DropdownItem id="underline" text-value="下划线">
|
|
<DropdownItemIndicator />
|
|
<Label>下划线</Label>
|
|
<Kbd class="ms-auto" slot="keyboard" variant="light">
|
|
<KbdAbbr key-value="command" />
|
|
<KbdContent>U</KbdContent>
|
|
</Kbd>
|
|
</DropdownItem>
|
|
</DropdownSection>
|
|
<Separator />
|
|
<DropdownSection
|
|
:selected-keys="textAlignment"
|
|
selection-mode="single"
|
|
@update:selected-keys="(keys: MenuKey[]) => (textAlignment = keys)"
|
|
>
|
|
<Header>文本对齐</Header>
|
|
<DropdownItem id="left" text-value="左对齐">
|
|
<DropdownItemIndicator type="dot" />
|
|
<Label>左对齐</Label>
|
|
<Kbd class="ms-auto" slot="keyboard" variant="light">
|
|
<KbdAbbr key-value="alt" />
|
|
<KbdContent>A</KbdContent>
|
|
</Kbd>
|
|
</DropdownItem>
|
|
<DropdownItem id="center" text-value="居中">
|
|
<DropdownItemIndicator type="dot" />
|
|
<Label>居中</Label>
|
|
<Kbd class="ms-auto" slot="keyboard" variant="light">
|
|
<KbdAbbr key-value="alt" />
|
|
<KbdContent>H</KbdContent>
|
|
</Kbd>
|
|
</DropdownItem>
|
|
<DropdownItem id="right" text-value="右对齐">
|
|
<DropdownItemIndicator type="dot" />
|
|
<Label>右对齐</Label>
|
|
<Kbd class="ms-auto" slot="keyboard" variant="light">
|
|
<KbdAbbr key-value="alt" />
|
|
<KbdContent>D</KbdContent>
|
|
</Kbd>
|
|
</DropdownItem>
|
|
</DropdownSection>
|
|
</DropdownMenu>
|
|
</DropdownPopover>
|
|
</DropdownRoot>
|
|
</template>
|