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:
@@ -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 存在性检查;真实挂载行为以本夹具的浏览器结果为准。
|
||||
@@ -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>
|
||||
@@ -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");
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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",
|
||||
};
|
||||
Reference in New Issue
Block a user