fix: menu selection ARIA, cancelable activation, submenu and long-press
- Selected items use menuitemradio/menuitemcheckbox + aria-checked + data-selected - onClick preventDefault cancels action/selection/close (user handlers first) - Submenu trigger is a single menuitem (asChild); standalone Menu owns Reka root - DropdownRoot trigger=longPress with threshold, keyboard fallback, cleanup - Export *Props types; independent tarball ESM/CSS + NodeNext/bundler contracts - Esc still closes the full submenu stack (recorded gap)
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import {
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownSection,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
type DropdownRootProps,
|
||||
type DropdownMenuProps,
|
||||
type DropdownItemProps,
|
||||
type DropdownItemIndicatorProps,
|
||||
type MenuRootProps,
|
||||
type MenuItemProps,
|
||||
type MenuItemIndicatorProps,
|
||||
type MenuSectionProps,
|
||||
type MenuKey,
|
||||
type MenuSelectionMode,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const mode: MenuSelectionMode = "multiple";
|
||||
const keys: MenuKey[] = ["a", 0, ""];
|
||||
|
||||
const root: DropdownRootProps = {
|
||||
trigger: "longPress",
|
||||
longPressDuration: 400,
|
||||
modal: true,
|
||||
dir: "rtl",
|
||||
};
|
||||
// @ts-expect-error unknown trigger mode
|
||||
const badTrigger: DropdownRootProps = { trigger: "hover" };
|
||||
|
||||
const menu: MenuRootProps = {
|
||||
selectionMode: mode,
|
||||
selectedKeys: keys,
|
||||
disabledKeys: ["b"],
|
||||
};
|
||||
// @ts-expect-error selectionMode must be none|single|multiple
|
||||
const badMode: MenuRootProps = { selectionMode: "multiple2" };
|
||||
|
||||
const item: MenuItemProps = {
|
||||
id: "a",
|
||||
textValue: "A",
|
||||
variant: "danger",
|
||||
isDisabled: true,
|
||||
closeOnSelect: false,
|
||||
};
|
||||
// @ts-expect-error variant is default|danger only
|
||||
const badVariant: MenuItemProps = { variant: "primary" };
|
||||
|
||||
const indicator: MenuItemIndicatorProps = { type: "dot" };
|
||||
// @ts-expect-error type is checkmark|dot
|
||||
const badIndicator: MenuItemIndicatorProps = { type: "cross" };
|
||||
|
||||
const section: MenuSectionProps = {
|
||||
selectionMode: "single",
|
||||
selectedKeys: ["x"],
|
||||
};
|
||||
|
||||
const dItem: DropdownItemProps = {
|
||||
id: "x",
|
||||
textValue: "X",
|
||||
variant: "default",
|
||||
};
|
||||
const dInd: DropdownItemIndicatorProps = { type: "checkmark" };
|
||||
const dMenu: DropdownMenuProps = { selectionMode: "none" };
|
||||
|
||||
export const parts = [
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownSection,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
] as const;
|
||||
|
||||
export const values = {
|
||||
root,
|
||||
menu,
|
||||
item,
|
||||
indicator,
|
||||
section,
|
||||
dItem,
|
||||
dInd,
|
||||
dMenu,
|
||||
badTrigger,
|
||||
badMode,
|
||||
badVariant,
|
||||
badIndicator,
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Independent ESM/CSS consumption for B01 Menu/Dropdown.
|
||||
* Copy into a fresh consumer that installs packed tarballs (no source alias).
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
const mod = await import("@heroui-vue/components");
|
||||
const {
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSection,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
} = mod;
|
||||
|
||||
const expected = {
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSection,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
};
|
||||
for (const [name, value] of Object.entries(expected)) {
|
||||
if (!value) {
|
||||
console.error("missing export", name);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const cssPath = import.meta.resolve("@heroui-vue/styles/css");
|
||||
const css = readFileSync(new URL(cssPath), "utf8");
|
||||
for (const token of [
|
||||
"hv-menu-item",
|
||||
"hv-menu-item__indicator--submenu",
|
||||
"hv-dropdown__popover",
|
||||
"hv-dropdown__menu",
|
||||
"data-selected",
|
||||
]) {
|
||||
if (!css.includes(token)) {
|
||||
console.error("css missing", token);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("b01 menu/dropdown ESM+CSS consume ok");
|
||||
Reference in New Issue
Block a user