fix: complete submenu panel ARIA, focus and event passthrough
- Submenu panel name priority is explicit aria-label > menu content channel > this instance's trigger; an explicit label drops the id reference so it cannot be shadowed. - openAutoFocus and animationend chain with the caller's handlers like keydown and interact-outside, so caller callbacks run and can cancel. - The panel loop falls back to the menu-level shouldFocusWrap and is always passed as a boolean: an undefined -> true update is dropped by the base prop chain, so the menu policy never applied. - Add a jsdom CSSOM polyfill for CSS.escape via vitest setupFiles; the animationend test no longer raises an unhandled error.
This commit is contained in:
@@ -341,3 +341,49 @@ it("standalone Menu keeps its own accessible name", async () => {
|
||||
document.querySelector('[role="menu"]')?.getAttribute("aria-label"),
|
||||
).toBe("Standalone actions");
|
||||
});
|
||||
|
||||
it("submenu keeps a directly supplied panel accessible name", async () => {
|
||||
const panel = await openConfiguredSubmenu({
|
||||
"aria-label": "Direct submenu name",
|
||||
"aria-describedby": "explicit-description",
|
||||
});
|
||||
expect(panel.getAttribute("aria-label")).toBe("Direct submenu name");
|
||||
expect(panel.getAttribute("aria-describedby")).toBe("explicit-description");
|
||||
});
|
||||
it("submenu preserves a caller's openAutoFocus callback", async () => {
|
||||
const callback = vi.fn();
|
||||
await openConfiguredSubmenu({ onOpenAutoFocus: callback });
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
it("submenu respects the menu's shouldFocusWrap navigation", async () => {
|
||||
await render({}, () =>
|
||||
h(DropdownSubmenuTrigger, {}, () => [
|
||||
h(DropdownItem, { id: "sub" }, () => [
|
||||
"Sub",
|
||||
h(DropdownSubmenuIndicator),
|
||||
]),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, { shouldFocusWrap: true }, () => [
|
||||
h(DropdownItem, { id: "first", textValue: "First" }, () => "First"),
|
||||
h(DropdownItem, { id: "last", textValue: "Last" }, () => "Last"),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
);
|
||||
(document.querySelector('[data-key="sub"]') as HTMLElement).click();
|
||||
await flushPromises();
|
||||
const panel = document.querySelector("[data-submenu-content]")!;
|
||||
const first = panel.querySelector('[data-key="first"]') as HTMLElement;
|
||||
const last = panel.querySelector('[data-key="last"]') as HTMLElement;
|
||||
first.focus();
|
||||
await flushPromises();
|
||||
first.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "ArrowUp",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
expect(document.activeElement).toBe(last);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user