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,106 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, h } from "vue";
|
||||
import {
|
||||
DropdownRoot,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
DropdownSubmenuIndicator,
|
||||
Menu,
|
||||
MenuItem,
|
||||
} from "../packages/vue/src";
|
||||
const cleanup: (() => void)[] = [];
|
||||
afterEach(() => {
|
||||
cleanup
|
||||
.splice(0)
|
||||
.reverse()
|
||||
.forEach((fn) => fn());
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
async function renderMenu(
|
||||
menuProps = {},
|
||||
itemProps = {},
|
||||
children = () => "A",
|
||||
) {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () =>
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, menuProps, () =>
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "a", textValue: "A", ...itemProps },
|
||||
children,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
cleanup.push(() => w.unmount());
|
||||
await flushPromises();
|
||||
return document.querySelector('[data-slot="menu-item"]') as HTMLElement;
|
||||
}
|
||||
it("selected multiple item exposes checked menu semantics and source CSS selected state", async () => {
|
||||
const node = await renderMenu(
|
||||
{ selectionMode: "multiple", selectedKeys: ["a"] },
|
||||
{},
|
||||
() => [h(DropdownItemIndicator, { type: "dot" }), "A"] as never,
|
||||
);
|
||||
expect(node.getAttribute("role")).toBe("menuitemcheckbox");
|
||||
expect(node.getAttribute("aria-checked")).toBe("true");
|
||||
});
|
||||
it("preventing click prevents action and default close", async () => {
|
||||
const action = vi.fn();
|
||||
const node = await renderMenu(
|
||||
{ onAction: action },
|
||||
{ onClick: (e: MouseEvent) => e.preventDefault() },
|
||||
);
|
||||
node.click();
|
||||
await flushPromises();
|
||||
expect(action).not.toHaveBeenCalled();
|
||||
expect(document.querySelector('[data-slot="menu-item"]')).not.toBeNull();
|
||||
});
|
||||
it("submenu trigger has one menuitem DOM node rather than nested interactive items", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () =>
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(DropdownSubmenuTrigger, {}, () => [
|
||||
h(DropdownItem, { id: "sub", textValue: "Sub" }, () => [
|
||||
"Sub",
|
||||
h(DropdownSubmenuIndicator),
|
||||
]),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(DropdownItem, { id: "child" }, () => "Child"),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
cleanup.push(() => w.unmount());
|
||||
await flushPromises();
|
||||
expect(
|
||||
document.querySelector('[role="menuitem"] [role="menuitem"]'),
|
||||
).toBeNull();
|
||||
});
|
||||
it("standalone exported Menu and MenuItem do not require an internal DropdownMenuRoot", () => {
|
||||
expect(() => {
|
||||
const w = mount(Menu, {
|
||||
slots: { default: () => h(MenuItem, { id: "a" }, () => "A") },
|
||||
});
|
||||
cleanup.push(() => w.unmount());
|
||||
}).not.toThrow();
|
||||
});
|
||||
Reference in New Issue
Block a user