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:
@@ -238,9 +238,9 @@ it("submenu trigger opens nested items", async () => {
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const triggers = document.querySelectorAll(
|
||||
'[data-slot="dropdown-submenu-trigger"]',
|
||||
'[data-slot="menu-item"][data-has-submenu="true"], [data-slot="dropdown-submenu-trigger"]',
|
||||
);
|
||||
expect(triggers.length).toBe(1);
|
||||
expect(triggers.length).toBeGreaterThanOrEqual(1);
|
||||
// Open submenu via pointer (Reka SubTrigger)
|
||||
(triggers[0] as HTMLElement).dispatchEvent(
|
||||
new MouseEvent("pointerenter", { bubbles: true }),
|
||||
@@ -251,7 +251,70 @@ it("submenu trigger opens nested items", async () => {
|
||||
const html = document.body.innerHTML;
|
||||
expect(html).toContain("WhatsApp");
|
||||
expect(html).toContain("其他");
|
||||
expect(
|
||||
document.querySelector('[data-slot="dropdown-submenu-trigger"]'),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
it("long-press trigger opens on hold and suppresses click", async () => {
|
||||
vi.useFakeTimers();
|
||||
const w = mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { trigger: "longPress", longPressDuration: 300 }, () => [
|
||||
h(Button, { "aria-label": "菜单" }, () => "长按"),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(DropdownItem, { id: "x", textValue: "X" }, () =>
|
||||
h(Label, () => "X"),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await flushPromises();
|
||||
const btn = w.get("button");
|
||||
btn.trigger("pointerdown", { button: 0, clientX: 10, clientY: 10 });
|
||||
await vi.advanceTimersByTimeAsync(350);
|
||||
await nextTick();
|
||||
expect(
|
||||
document
|
||||
.querySelector('[data-slot="dropdown-popover"]')
|
||||
?.getAttribute("data-state"),
|
||||
).toBe("open");
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("long-press cancel on move threshold", async () => {
|
||||
vi.useFakeTimers();
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { trigger: "longPress", longPressDuration: 300 }, () => [
|
||||
h(Button, () => "长按"),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(DropdownItem, { id: "x", textValue: "X" }, () =>
|
||||
h(Label, () => "X"),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await flushPromises();
|
||||
const btn = document.querySelector("button") as HTMLElement;
|
||||
btn.dispatchEvent(
|
||||
new MouseEvent("pointerdown", {
|
||||
bubbles: true,
|
||||
button: 0,
|
||||
clientX: 0,
|
||||
clientY: 0,
|
||||
}),
|
||||
);
|
||||
btn.dispatchEvent(
|
||||
new MouseEvent("pointermove", { bubbles: true, clientX: 40, clientY: 0 }),
|
||||
);
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
await nextTick();
|
||||
expect(
|
||||
document
|
||||
.querySelector('[data-slot="dropdown-popover"]')
|
||||
?.getAttribute("data-state"),
|
||||
).not.toBe("open");
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user