The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Top bar menus: arrow keys keep a pointer-opened menu open
Adarshb8668905c236
diff --git a/src/components/nav/bar-menus.tsx b/src/components/nav/bar-menus.tsxindex 386215b3..92bc8aa1 100644--- a/src/components/nav/bar-menus.tsx+++ b/src/components/nav/bar-menus.tsx@@ -90,6 +90,8 @@ export const shows = (el: Element) =>typeof (el as HTMLElement).checkVisibility === "function" ? (el as HTMLElement).checkVisibility() : el.getClientRects().length > 0;const now = () => performance.now();+/** Keys that move focus inside an open menu. */+const MOVE_KEYS = new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "Tab"]);const isKeyboard = () => typeof document !== "undefined" && document.documentElement.dataset.input === "keyboard";const box = (el: Element | null | undefined): Box | null => {if (!el) return null;@@ -378,6 +380,12 @@ export function createBarController(act: (a: BarMenuAction) => BarMenuState, staif ((e.target as Element).closest("a[href]")) close(id);},onKeyDown(e) {+ // Keys moving inside a menu the pointer opened take it over: it no longer closes as the pointer leaves.+ const s = state();+ if (MOVE_KEYS.has(e.key) && s.id === id && s.mode === "hover") {+ if (timer?.kind === "close") clear();+ act({ type: "keys", id });+ }gridKey(e);},};diff --git a/src/components/nav/mega-launcher.tsx b/src/components/nav/mega-launcher.tsxindex c2d960d0..68c67dc9 100644--- a/src/components/nav/mega-launcher.tsx+++ b/src/components/nav/mega-launcher.tsx@@ -144,7 +144,7 @@ export function MegaLauncher({ id, active, className }: { id: MegaId; active?: b/* Spoken "Studios, 29 studios": the visible words start the name (no separate label to drift from them). */<span className="inline-flex items-center gap-1.5">{area.label}- <span className="sr-only">,</span>+ <span className="sr-only">, </span><span className="rounded-full bg-brand-faint px-1.5 py-px text-[11px] leading-4 font-semibold text-brand-text tabular-nums">{n}</span><span className="sr-only"> studios</span></span>diff --git a/src/lib/bar-intent.ts b/src/lib/bar-intent.tsindex fc08c95c..271f8f36 100644--- a/src/lib/bar-intent.ts+++ b/src/lib/bar-intent.ts@@ -50,6 +50,8 @@ export type BarMenuAction =* pointer opened marks it clicked (a tap also pins it); a click on a clicked one closes it.*/| { type: "click"; id: BarMenuId; via: MenuVia; now: number }+ /** Keys pressed inside the open menu `id` took it over: it no longer closes as the pointer leaves (the next click does). */+ | { type: "keys"; id: BarMenuId }/** Close the open menu, or (with `id`) only if `id` is the open one. */| { type: "close"; id?: BarMenuId; now: number };@@ -74,6 +76,8 @@ export function barMenus(s: BarMenuState, a: BarMenuAction): BarMenuState {}return barMenus(s, { type: "open", id: a.id, mode: mouse ? "hover" : "pinned", via: a.via, clicked: true, now: a.now });}+ case "keys":+ return s.id === a.id && s.mode !== "pinned" ? { ...s, mode: "pinned", clicked: true } : s;case "close": {if (s.id === null || (a.id !== undefined && a.id !== s.id)) return s;return { ...s, id: null, prev: null, group: undefined, mode: "hover", clicked: false, closedAt: a.now };diff --git a/tests/bar-intent.test.ts b/tests/bar-intent.test.tsindex a0fae750..c024a38c 100644--- a/tests/bar-intent.test.ts+++ b/tests/bar-intent.test.ts@@ -41,6 +41,14 @@ describe("the menu state", () => {expect(barMenus(closed, { type: "close", now: 20 })).toBe(closed);});+ it("keys pressed inside a menu the pointer opened pin it (leaving no longer closes it); for another menu they do nothing", () => {+ const s = open(CLOSED_MENUS, "create");+ const k = barMenus(s, { type: "keys", id: "create" });+ expect(k).toMatchObject({ id: "create", mode: "pinned", clicked: true, seq: s.seq, prev: s.prev });+ expect(barMenus(s, { type: "keys", id: "apps" })).toBe(s);+ expect(barMenus(k, { type: "keys", id: "create" })).toBe(k);+ });+it("a mouse click never pins: on a menu the pointer opened it only marks it clicked; the next click closes it", () => {const hover = open(CLOSED_MENUS, "create");const clicked = barMenus(hover, { type: "click", id: "create", via: "pointer", now: 30 });diff --git a/tests/nav-bar.test.ts b/tests/nav-bar.test.tsindex 49c41c15..bada7777 100644--- a/tests/nav-bar.test.ts+++ b/tests/nav-bar.test.ts@@ -454,7 +454,7 @@ describe("menu items: one button each, the area's page inside its menu", () => {expect(item(html, "more")).not.toContain("data-href");// Its spoken name starts with its visible words ("Studios, 29 studios"): the count's words are hidden text, not a label.expect(item(html, "studios")).not.toContain("aria-label=");- expect(html).toMatch(new RegExp(`Studios<span class="sr-only">,</span><span[^>]*>${studioCount()}</span><span class="sr-only"> studios</span>`));+ expect(html).toMatch(new RegExp(`Studios<span class="sr-only">, </span><span[^>]*>${studioCount()}</span><span class="sr-only"> studios</span>`));// The Studios item is still the launcher's disclosure button (search hands focus back to it).expect(item(html, "studios")).toContain("data-studios-trigger");for (const name of ["Create menu", "Studios menu", "Apps menu", "Motions & effects menu", "Canvas menu"]) expect(html, name).not.toContain(`aria-label="${name}"`);