Files
heroui-vue/tests/package/b01-consumer-app/main.js
T
maoyingjie 53b4639b0e 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.
2026-10-24 22:56:44 +08:00

215 lines
6.7 KiB
JavaScript

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");