Files
heroui-vue/apps/docs/demos/dropdown-with-single-selection.vue
maoyingjie 06ddb6662a feat: migrate Menu and Dropdown with selection and submenus
Port HeroUI menu family and Dropdown from ce90ea3: Reka DropdownMenu base,
MenuKey[] selection with section owners, 17 official demos, dropdown docs
and B01 tests. Long-press stays demo-level; submenu close is level-scoped.
2026-10-24 20:43:04 +08:00

57 lines
1.6 KiB
Vue

<script setup lang="ts">
import { 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"]);
</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 />
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator />
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator />
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator />
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator />
<Label>梨</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>