fix: portal dropdown surfaces and close the review capability gaps

- Root and submenu surfaces render through the dropdown portal with the overlay
  z-index, so clipping/isolation ancestors no longer cut the menu; panel height
  is capped by the floating available height and the animation origin maps the
  real transform origin.
- Standalone Menu is a static in-flow list: no scroll lock, no outside pointer
  blocking, no floating placement and no focus stealing.
- Selection ownership is isolated per level: section disabled keys add to the
  menu list, and a nested Menu resets the section owner.
- closeOnSelect resolves item > menu policy > per-mode default for selection
  items; actions and radio items close, checkboxes stay open.
- Business keys no longer become DOM ids (instance ids + data-key), and submenu
  surfaces label themselves from the real trigger.
- Long-press keydown runs the caller's handlers first and only opens when not
  cancelled; submenu panels merge caller keydown with the internal Escape.
- Link items render a real anchor, aria labels land on the role=menu node,
  submenu panels forward placement/offset/collision props and caller attrs, and
  the popover provides the default Surface variant.
- Wrapper parts declare real props/emits, plus the missing official capability
  props (disallowEmptySelection, escapeKeyBehavior, shouldFocusWrap, autoFocus,
  shouldCloseOnSelect, close, empty slot, isKeyboardDismissDisabled,
  shouldCloseOnInteractOutside, placement/offset family, scoped slots).
- Ship an independent consumer fixture for browser-level verification.
This commit is contained in:
maoyingjie
2026-10-24 22:56:44 +08:00
parent 043a5418f3
commit 53b4639b0e
25 changed files with 1721 additions and 203 deletions
+243
View File
@@ -0,0 +1,243 @@
import Surface from "../packages/vue/src/components/surface/Surface.vue";
import { surfaceContextKey } from "../packages/vue/src/components/surface/context";
import { afterEach, expect, it, vi } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { defineComponent, h, ref, inject } from "vue";
import {
Button,
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownSection,
DropdownSubmenuTrigger,
DropdownSubmenuIndicator,
DropdownItem,
Menu,
} from "../packages/vue/src";
const cleanup: (() => void)[] = [];
afterEach(() => {
cleanup
.splice(0)
.reverse()
.forEach((fn) => fn());
vi.useRealTimers();
document.body.innerHTML = "";
});
async function render(
menuProps: Record<string, unknown>,
children: () => unknown,
) {
const w = mount(
defineComponent({
setup: () => () =>
h(DropdownRoot, { defaultOpen: true, modal: false }, () =>
h(DropdownPopover, {}, () =>
h(DropdownMenu, menuProps, { default: children }),
),
),
}),
{ attachTo: document.body },
);
cleanup.push(() => w.unmount());
await flushPromises();
return w;
}
it("section disabledKeys work when selection is inherited", async () => {
await render({ selectionMode: "multiple" }, () =>
h(DropdownSection, { disabledKeys: ["x"] }, () =>
h(DropdownItem, { id: "x" }, () => "X"),
),
);
expect(
document
.querySelector('[data-slot="menu-item"]')
?.getAttribute("aria-disabled"),
).toBe("true");
});
it("root disabledKeys remain effective in a section with its own selection", async () => {
await render({ disabledKeys: ["x"] }, () =>
h(DropdownSection, { selectionMode: "multiple" }, () =>
h(DropdownItem, { id: "x" }, () => "X"),
),
);
expect(
document
.querySelector('[data-slot="menu-item"]')
?.getAttribute("aria-disabled"),
).toBe("true");
});
it("single-selection closeOnSelect=false keeps the menu open", async () => {
await render({ selectionMode: "single" }, () =>
h(DropdownItem, { id: "x", closeOnSelect: false }, () => "X"),
);
(document.querySelector('[data-slot="menu-item"]') as HTMLElement).click();
await flushPromises();
expect(document.querySelector('[data-slot="menu-item"]')).not.toBeNull();
});
it("multiple-selection closeOnSelect=true closes the menu", async () => {
await render({ selectionMode: "multiple" }, () =>
h(DropdownItem, { id: "x", closeOnSelect: true }, () => "X"),
);
(document.querySelector('[data-slot="menu-item"]') as HTMLElement).click();
await flushPromises();
expect(document.querySelector('[data-slot="menu-item"]')).toBeNull();
});
it("typed numeric and string keys never create duplicate DOM ids", async () => {
await render({ selectionMode: "multiple" }, () => [
h(DropdownItem, { id: 0 }, () => "Number"),
h(DropdownItem, { id: "0" }, () => "String"),
]);
const nodes = Array.from(
document.querySelectorAll('[data-slot="menu-item"]'),
);
expect(new Set(nodes.map((n) => n.id)).size).toBe(nodes.length);
});
it("standalone Menu does not lock body scrolling or disable outside controls", async () => {
const outside = document.createElement("button");
document.body.append(outside);
const w = mount(Menu, {
slots: { default: () => h(DropdownItem, { id: "x" }, () => "X") },
attachTo: document.body,
});
cleanup.push(() => w.unmount());
await flushPromises();
expect(document.body.style.overflow).not.toBe("hidden");
expect(document.body.style.pointerEvents).not.toBe("none");
expect(outside.getAttribute("aria-hidden")).not.toBe("true");
});
it("native link menu items retain anchor href semantics", async () => {
await render({}, () =>
h(
DropdownItem,
{ id: "link", href: "/target", target: "_blank" },
() => "Go",
),
);
const item = document.querySelector('[data-slot="menu-item"]')!;
expect(item.tagName).toBe("A");
expect(item.getAttribute("href")).toBe("/target");
});
it("longPress cannot open a disabled actual trigger", async () => {
vi.useFakeTimers();
const w = mount(
defineComponent({
setup: () => () =>
h(DropdownRoot, { trigger: "longPress", modal: false }, () => [
h(DropdownTrigger, {}, () =>
h(Button, { isDisabled: true }, () => "Hold"),
),
h(DropdownPopover, {}, () =>
h(DropdownMenu, {}, () => h(DropdownItem, { id: "x" }, () => "X")),
),
]),
}),
{ attachTo: document.body },
);
cleanup.push(() => w.unmount());
await w.get("button").trigger("pointerdown", {
pointerType: "mouse",
button: 0,
isPrimary: true,
});
await vi.advanceTimersByTimeAsync(600);
await flushPromises();
expect(document.querySelector('[data-slot="menu-item"]')).toBeNull();
});
it("cancelled trigger keydown does not open longPress menu", async () => {
const w = mount(
defineComponent({
setup: () => () =>
h(DropdownRoot, { trigger: "longPress", modal: false }, () => [
h(
DropdownTrigger,
{ onKeydown: (e: KeyboardEvent) => e.preventDefault() },
() => h(Button, {}, () => "Hold"),
),
h(DropdownPopover, {}, () =>
h(DropdownMenu, {}, () => h(DropdownItem, { id: "x" }, () => "X")),
),
]),
}),
{ attachTo: document.body },
);
cleanup.push(() => w.unmount());
await w.get("button").trigger("keydown", { key: "Enter" });
await flushPromises();
expect(document.querySelector('[data-slot="menu-item"]')).toBeNull();
});
it("root menu's accessible name follows its labelled DropdownMenu", async () => {
await render({ "aria-label": "File actions" }, () =>
h(DropdownItem, { id: "x" }, () => "X"),
);
const menu = document.querySelector('[role="menu"]')!;
expect(menu.getAttribute("aria-label")).toBe("File actions");
});
it("submenu Menu owns its selection instead of inheriting a parent section owner", async () => {
await render({}, () =>
h(
DropdownSection,
{ selectionMode: "multiple", selectedKeys: ["outer"] },
() =>
h(DropdownMenu, { selectionMode: "none" }, () =>
h(DropdownItem, { id: "inner" }, () => "Inner"),
),
),
);
expect(
document.querySelector('[data-slot="menu-item"]')?.getAttribute("role"),
).toBe("menuitem");
});
it("dropdown popover resets inherited Surface context like the fixed upstream", async () => {
const Inspector = defineComponent({
setup() {
const ctx = inject(surfaceContextKey, null);
return () =>
h("span", { "data-test": "surface" }, ctx?.variant.value ?? "none");
},
});
const w = mount(
defineComponent({
setup: () => () =>
h(Surface, { variant: "secondary" }, () =>
h(DropdownRoot, { defaultOpen: true, modal: false }, () =>
h(DropdownPopover, {}, () => h(Inspector)),
),
),
}),
{ attachTo: document.body },
);
cleanup.push(() => w.unmount());
await flushPromises();
expect(document.querySelector('[data-test="surface"]')?.textContent).toBe(
"default",
);
});
it("submenu panel preserves a caller keydown listener", async () => {
const keydown = vi.fn();
await render({}, () =>
h(DropdownSubmenuTrigger, {}, () => [
h(DropdownItem, { id: "sub" }, () => [
"Sub",
h(DropdownSubmenuIndicator),
]),
h(DropdownPopover, { onKeydown: keydown }, () =>
h(DropdownMenu, {}, () =>
h(DropdownItem, { id: "inner" }, () => "Inner"),
),
),
]),
);
(document.querySelector('[data-slot="menu-item"]') as HTMLElement).click();
await flushPromises();
const panel = document.querySelector("[data-submenu-content]")!;
expect(panel).not.toBeNull();
panel.dispatchEvent(
new KeyboardEvent("keydown", { key: "a", bubbles: true, cancelable: true }),
);
await flushPromises();
expect(keydown).toHaveBeenCalledTimes(1);
});
+254 -12
View File
@@ -20,6 +20,7 @@ import {
MenuItem,
MenuSection,
} from "../packages/vue/src";
import type { MenuKey } from "../packages/vue/src";
const cleanup: (() => void)[] = [];
afterEach(() => {
@@ -45,13 +46,13 @@ function mountApp(setup: () => unknown, render?: () => unknown) {
}
it("Dropdown opens and action item fires once", async () => {
const actions: string[] = [];
const actions: MenuKey[] = [];
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true }, () => [
h(Button, () => "操作"),
h(DropdownPopover, {}, () =>
h(DropdownMenu, { onAction: (k: string) => actions.push(k) }, () => [
h(DropdownMenu, { onAction: (k: MenuKey) => actions.push(k) }, () => [
h(DropdownItem, { id: "new-file", textValue: "新建文件" }, () =>
h(Label, () => "新建文件"),
),
@@ -343,7 +344,7 @@ function pointer(
}
function mountLongPress(duration = 300) {
const actions: string[] = [];
const actions: MenuKey[] = [];
const w = mountApp(
() => () =>
h(
@@ -354,7 +355,7 @@ function mountLongPress(duration = 300) {
h(Button, { "aria-label": "菜单" }, () => "长按"),
),
h(DropdownPopover, {}, () =>
h(DropdownMenu, { onAction: (k: string) => actions.push(k) }, () =>
h(DropdownMenu, { onAction: (k: MenuKey) => actions.push(k) }, () =>
h(DropdownItem, { id: "x", textValue: "X" }, () =>
h(Label, () => "X"),
),
@@ -585,13 +586,13 @@ it("Escape on a pointer-opened submenu trigger closes only that level", async ()
});
it("keyboard activation on a focused item fires the action once", async () => {
const actions: string[] = [];
const actions: MenuKey[] = [];
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true }, () => [
h(DropdownTrigger, {}, () => h(Button, () => "菜单")),
h(DropdownPopover, {}, () =>
h(DropdownMenu, { onAction: (k: string) => actions.push(k) }, () =>
h(DropdownMenu, { onAction: (k: MenuKey) => actions.push(k) }, () =>
h(DropdownItem, { id: "new-file", textValue: "新建文件" }, () =>
h(Label, () => "新建文件"),
),
@@ -617,13 +618,13 @@ it("keyboard activation on a focused item fires the action once", async () => {
});
it("keyboard activation is cancelled when the item click is prevented", async () => {
const actions: string[] = [];
const actions: MenuKey[] = [];
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true }, () => [
h(DropdownTrigger, {}, () => h(Button, () => "菜单")),
h(DropdownPopover, {}, () =>
h(DropdownMenu, { onAction: (k: string) => actions.push(k) }, () =>
h(DropdownMenu, { onAction: (k: MenuKey) => actions.push(k) }, () =>
h(
DropdownItem,
{
@@ -702,8 +703,12 @@ it("menu items expose DOM ids and a single role=menu per popup", async () => {
);
await flushPromises();
await nextTick();
const items = document.querySelectorAll('[data-slot="menu-item"]');
expect(Array.from(items).map((item) => item.getAttribute("id"))).toEqual([
const items = Array.from(
document.querySelectorAll('[data-slot="menu-item"]'),
);
// Business keys stay out of the DOM; each instance gets its own id.
expect(new Set(items.map((item) => item.id)).size).toBe(items.length);
expect(items.map((item) => item.getAttribute("data-key"))).toEqual([
"first",
"second",
]);
@@ -872,7 +877,7 @@ it("caller classes merge with tailwind-variants semantics", async () => {
});
it("pressing the submenu trigger without an indicator still treats it as a submenu", async () => {
const actions: string[] = [];
const actions: MenuKey[] = [];
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true }, () => [
@@ -880,7 +885,7 @@ it("pressing the submenu trigger without an indicator still treats it as a subme
h(DropdownPopover, {}, () =>
h(
DropdownMenu,
{ onAction: (key: string) => actions.push(key) },
{ onAction: (key: MenuKey) => actions.push(key) },
() =>
h(DropdownSubmenuTrigger, {}, () => [
h(DropdownItem, { id: "more", textValue: "更多" }, () =>
@@ -914,3 +919,240 @@ it("pressing the submenu trigger without an indicator still treats it as a subme
document.querySelectorAll('[data-slot="dropdown-popover"]').length,
).toBeGreaterThan(1);
});
it("menu capability props are honoured", async () => {
const close = vi.fn();
const selections: MenuKey[][] = [];
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true, modal: false }, () => [
h(DropdownPopover, {}, () =>
h(
DropdownMenu,
{
selectionMode: "multiple",
selectedKeys: ["a"],
disallowEmptySelection: true,
escapeKeyBehavior: "clearSelection",
shouldFocusWrap: true,
autoFocus: false,
onClose: close,
"onUpdate:selectedKeys": (keys: MenuKey[]) =>
selections.push(keys),
},
() =>
h(DropdownItem, { id: "a", textValue: "A" }, () =>
h(Label, () => "A"),
),
),
),
]),
);
await flushPromises();
await nextTick();
const menu = document.querySelector('[role="menu"]') as HTMLElement;
const item = document.querySelector('[data-slot="menu-item"]') as HTMLElement;
// disallowEmptySelection keeps the last key.
item.click();
await flushPromises();
expect(selections).toEqual([]);
// escapeKeyBehavior clears the selection instead of closing.
menu.dispatchEvent(
new KeyboardEvent("keydown", {
key: "Escape",
bubbles: true,
cancelable: true,
}),
);
await flushPromises();
expect(selections).toEqual([]);
expect(document.querySelector('[data-slot="menu-item"]')).not.toBeNull();
// close fires when the level actually closes.
menu.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" }));
await flushPromises();
});
it("link items render an anchor and keep navigation semantics", async () => {
const actions: MenuKey[] = [];
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true, modal: false }, () => [
h(DropdownPopover, {}, () =>
h(
DropdownMenu,
{ onAction: (key: MenuKey) => actions.push(key) },
() =>
h(
DropdownItem,
{
id: "link",
href: "/target",
target: "_blank",
rel: "noopener",
},
() => h(Label, () => "Go"),
),
),
),
]),
);
await flushPromises();
await nextTick();
const link = document.querySelector('[data-slot="menu-item"]') as HTMLElement;
expect(link.tagName).toBe("A");
expect(link.getAttribute("href")).toBe("/target");
expect(link.getAttribute("target")).toBe("_blank");
expect(link.getAttribute("rel")).toBe("noopener");
expect(link.getAttribute("role")).toBe("menuitem");
link.click();
await flushPromises();
expect(actions).toEqual(["link"]);
});
it("disabled link items do not navigate", async () => {
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true, modal: false }, () => [
h(DropdownPopover, {}, () =>
h(DropdownMenu, {}, () =>
h(
DropdownItem,
{ id: "link", href: "/target", isDisabled: true },
() => h(Label, () => "Go"),
),
),
),
]),
);
await flushPromises();
await nextTick();
const link = document.querySelector('[data-slot="menu-item"]') as HTMLElement;
const event = new MouseEvent("click", { bubbles: true, cancelable: true });
link.dispatchEvent(event);
expect(event.defaultPrevented).toBe(true);
});
it("empty slot renders when the menu has no items", async () => {
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true, modal: false }, () => [
h(DropdownPopover, {}, () =>
h(
DropdownMenu,
{},
{
empty: () => h("p", { "data-test": "empty" }, "无结果"),
},
),
),
]),
);
await flushPromises();
await nextTick();
expect(document.querySelector('[data-test="empty"]')).not.toBeNull();
});
it("submenu panel receives panel props and keeps caller handlers", async () => {
const keydown = vi.fn();
mountApp(
() => () =>
h(DropdownRoot, { defaultOpen: true, modal: false }, () => [
h(DropdownPopover, {}, () =>
h(DropdownMenu, {}, () =>
h(DropdownSubmenuTrigger, {}, () => [
h(DropdownItem, { id: "sub", textValue: "S" }, () => [
h(Label, () => "S"),
h(DropdownSubmenuIndicator),
]),
h(
DropdownPopover,
{
sideOffset: 12,
collisionPadding: 20,
class: "panel-x",
onKeydown: keydown,
},
() =>
h(DropdownMenu, {}, () =>
h(DropdownItem, { id: "inner", textValue: "I" }, () =>
h(Label, () => "I"),
),
),
),
]),
),
),
]),
);
await flushPromises();
await nextTick();
(document.querySelector('[data-slot="menu-item"]') as HTMLElement).click();
await flushPromises();
await nextTick();
const panel = document.querySelector("[data-submenu-content]") as HTMLElement;
expect(panel.className).toContain("panel-x");
// Portal keeps the panel outside the clipping ancestor.
expect(panel.closest('[data-slot="dropdown-popover"]')).toBe(panel);
panel.dispatchEvent(
new KeyboardEvent("keydown", { key: "a", bubbles: true, cancelable: true }),
);
await flushPromises();
expect(keydown).toHaveBeenCalledTimes(1);
});
it("dropdown popover is portaled out of clipping ancestors", async () => {
const host = document.createElement("div");
host.style.overflow = "hidden";
host.style.isolation = "isolate";
document.body.append(host);
const w = mount(
defineComponent({
setup: () => () =>
h(DropdownRoot, { defaultOpen: true, modal: false }, () => [
h(DropdownTrigger, {}, () => h(Button, () => "菜单")),
h(DropdownPopover, {}, () =>
h(DropdownMenu, {}, () =>
h(DropdownItem, { id: "a", textValue: "A" }, () =>
h(Label, () => "A"),
),
),
),
]),
}),
{ attachTo: host },
);
cleanup.push(() => w.unmount());
await flushPromises();
await nextTick();
const popover = document.querySelector(
'[data-slot="dropdown-popover"]',
) as HTMLElement;
expect(popover).not.toBeNull();
expect(host.contains(popover)).toBe(false);
expect(popover.closest("[data-reka-popper-content-wrapper]")).toBe(
popover.parentElement,
);
});
it("standalone Menu stays in flow without modal side effects", async () => {
const outside = document.createElement("button");
document.body.append(outside);
const w = mount(Menu, {
slots: { default: () => h(MenuItem, { id: "x" }, () => "X") },
attachTo: document.body,
});
cleanup.push(() => w.unmount());
await flushPromises();
await nextTick();
const surface = document.querySelector(
"[data-reka-menu-content]",
) as HTMLElement;
expect(surface.getAttribute("data-static")).toBe("true");
expect(document.body.style.overflow).not.toBe("hidden");
expect(outside.getAttribute("aria-hidden")).not.toBe("true");
// Focus is not stolen from the page.
expect(document.activeElement).not.toBe(surface);
});
+29
View File
@@ -0,0 +1,29 @@
# B01 独立浏览器消费夹具
用打包产物(`pnpm pack` 生成的 `@heroui-vue/components` / `@heroui-vue/styles` tarball)在独立 Vue 应用中真实挂载,覆盖:
- `selection`:带 `contain/isolation/overflow:hidden` 祖先的分组级多选长菜单(验证 Portal 脱离裁切、高度上限、真实 `role="menu"` 名称)。
- `submenu`:三级子菜单 + 链接型菜单项。
- `modal`:Modal 内的 Dropdown(验证层级与关闭顺序、滚动锁释放)。
- `standalone`:独立 `Menu` 内联列表(无滚动锁、无浮动定位、不抢焦点)。
## 使用方式
```bash
# 1. 在库仓库打包
pnpm build
pnpm --filter @heroui-vue/styles exec pnpm pack --pack-destination /tmp/heroui-b01-consumer
pnpm --filter @heroui-vue/components exec pnpm pack --pack-destination /tmp/heroui-b01-consumer
# 2. 复制本目录到消费工程并安装
cp -R tests/package/b01-consumer-app/. /tmp/heroui-b01-consumer/app/
cd /tmp/heroui-b01-consumer && pnpm install
# 3. 打包成静态产物(esbuild 只作为构建工具,运行期仅依赖 tarball)
esbuild app/main.js --bundle --format=esm --outfile=app/bundle.js --loader:.css=css
# 4. 静态服务后打开(`?only=selection|submenu|modal|standalone` 可单例)
python3 -m http.server 5199 --bind 127.0.0.1 --directory app
```
`consume-b01-menu-dropdown.mjs` 只做导出/CSS 存在性检查;真实挂载行为以本夹具的浏览器结果为准。
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title>B01 consumer</title>
<link rel="stylesheet" href="./bundle.css" />
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div id="app"></div>
<script type="module" src="./bundle.js"></script>
</body>
</html>
+214
View File
@@ -0,0 +1,214 @@
import { createApp, h, ref, defineComponent } from "vue";
import {
Button,
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownSection,
DropdownItem,
DropdownItemIndicator,
DropdownSubmenuTrigger,
DropdownSubmenuIndicator,
Header,
Label,
Menu,
MenuItem,
Modal,
ModalTrigger,
ModalBackdrop,
ModalContainer,
ModalDialog,
ModalHeader,
ModalHeading,
ModalBody,
ModalFooter,
ModalCloseTrigger,
} from "@heroui-vue/components";
import "@heroui-vue/styles/css";
const selected = ref(["a"]);
const actions = [];
window.__actions = actions;
const fruits = ["a", "b", "c", "d", "e", "f", "g", "h"];
const names = ["苹果", "香蕉", "樱桃", "橙子", "梨", "葡萄", "西瓜", "芒果"];
const SelectionCase = defineComponent({
name: "SelectionCase",
setup() {
return () =>
h("div", { "data-case": "clipping", class: "clip-ancestor" }, [
h(DropdownRoot, { modal: false }, () => [
h(DropdownTrigger, null, () =>
h(Button, { "aria-label": "水果" }, () => "选择水果"),
),
h(DropdownPopover, null, () =>
h(
DropdownMenu,
{
"aria-label": "水果操作",
selectionMode: "multiple",
selectedKeys: selected.value,
"onUpdate:selectedKeys": (k) => (selected.value = k),
},
() =>
h(DropdownSection, null, () => [
h(Header, null, () => "水果"),
...fruits.map((id, index) =>
h(DropdownItem, { id, textValue: names[index] }, () => [
h(DropdownItemIndicator),
h(Label, null, () => names[index]),
]),
),
]),
),
),
]),
]);
},
});
const SubmenuCase = defineComponent({
name: "SubmenuCase",
setup() {
return () =>
h("div", { "data-case": "submenu", class: "case" }, [
h(DropdownRoot, { modal: false }, () => [
h(DropdownTrigger, null, () =>
h(Button, { "aria-label": "分享" }, () => "分享"),
),
h(DropdownPopover, null, () =>
h(
DropdownMenu,
{ onAction: (k) => actions.push(String(k)) },
() => [
h(DropdownItem, { id: "copy", textValue: "复制链接" }, () =>
h(Label, null, () => "复制链接"),
),
h(DropdownSubmenuTrigger, null, () => [
h(DropdownItem, { id: "more", textValue: "更多" }, () => [
h(Label, null, () => "更多"),
h(DropdownSubmenuIndicator),
]),
h(DropdownPopover, null, () =>
h(DropdownMenu, null, () => [
h(DropdownItem, { id: "wa", textValue: "WhatsApp" }, () =>
h(Label, null, () => "WhatsApp"),
),
h(DropdownItem, { id: "tg", textValue: "Telegram" }, () =>
h(Label, null, () => "Telegram"),
),
h(DropdownSubmenuTrigger, null, () => [
h(
DropdownItem,
{ id: "mail", textValue: "邮件" },
() => [
h(Label, null, () => "邮件"),
h(DropdownSubmenuIndicator),
],
),
h(DropdownPopover, null, () =>
h(DropdownMenu, null, () =>
h(
DropdownItem,
{ id: "work", textValue: "工作邮箱" },
() => h(Label, null, () => "工作邮箱"),
),
),
),
]),
]),
),
]),
h(
DropdownItem,
{ id: "link", textValue: "文档", href: "#docs" },
() => h(Label, null, () => "文档链接"),
),
],
),
),
]),
]);
},
});
const ModalCase = defineComponent({
name: "ModalCase",
setup() {
return () =>
h("div", { "data-case": "modal", class: "case" }, [
h(Modal, null, () => [
h(ModalTrigger, null, () => h(Button, null, () => "打开组合复核")),
h(ModalBackdrop, null, () =>
h(ModalContainer, null, () =>
h(ModalDialog, null, () => [
h(ModalHeader, null, () =>
h(ModalHeading, null, () => "模态内菜单"),
),
h(ModalBody, null, () => [
h(DropdownRoot, { modal: false }, () => [
h(DropdownTrigger, null, () =>
h(Button, { "aria-label": "菜单" }, () => "菜单"),
),
h(DropdownPopover, null, () =>
h(DropdownMenu, null, () => [
h(DropdownItem, { id: "m1", textValue: "一" }, () =>
h(Label, null, () => "一"),
),
h(DropdownItem, { id: "m2", textValue: "二" }, () =>
h(Label, null, () => "二"),
),
]),
),
]),
]),
h(ModalFooter, null, () =>
h(ModalCloseTrigger, null, () =>
h(Button, null, () => "关闭"),
),
),
]),
),
),
]),
]);
},
});
const StandaloneCase = defineComponent({
name: "StandaloneCase",
setup() {
return () =>
h("div", { "data-case": "standalone", class: "case" }, [
h(Menu, { "aria-label": "内联菜单" }, () => [
h(MenuItem, { id: "s1" }, () => "内联项一"),
h(MenuItem, { id: "s2" }, () => "内联项二"),
]),
]);
},
});
const only = new URLSearchParams(location.search).get("only");
const cases = {
selection: SelectionCase,
submenu: SubmenuCase,
modal: ModalCase,
standalone: StandaloneCase,
};
const shown = only && cases[only] ? [cases[only]] : Object.values(cases);
createApp(
defineComponent({
name: "App",
setup() {
return () =>
h(
"main",
{ style: "display:flex;flex-direction:column;gap:16px;padding:16px" },
shown.map((component) => h(component)),
);
},
}),
).mount("#app");
+16
View File
@@ -0,0 +1,16 @@
body {
margin: 0;
font-family: -apple-system, "PingFang SC", sans-serif;
}
.clip-ancestor {
overflow: hidden;
contain: content;
isolation: isolate;
height: 64px;
border: 1px dashed #bbb;
}
.case {
display: flex;
gap: 12px;
align-items: flex-start;
}
+18
View File
@@ -0,0 +1,18 @@
import {
DropdownItem,
DropdownMenu,
DropdownSection,
} from "@heroui-vue/components";
// Valid API values must be accepted by the actual public Vue component types,
// not only by separately exported aliases.
export const item: InstanceType<typeof DropdownItem>["$props"] = {
id: "item",
variant: "danger",
};
export const menu: InstanceType<typeof DropdownMenu>["$props"] = {
selectionMode: "multiple",
selectedKeys: [0, "0"],
};
export const section: InstanceType<typeof DropdownSection>["$props"] = {
selectionMode: "single",
};