Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): restore sidebar focus after submenu Escape
Xubin Ren1ea981e417ae
diff --git a/docs/webui.md b/docs/webui.mdindex 8ccf02bc1..ba4479ae0 100644--- a/docs/webui.md+++ b/docs/webui.md@@ -115,7 +115,9 @@ On touch devices, sidebar action buttons stay visible with larger touch areasfor topics, conversation groups, panes, and projects. Tap a title to select itor the adjacent action button for its menu. Desktop actions still appear onhover or keyboard focus. Press Escape in an action menu to return focus to its-button and continue with Tab. Choosing Rename instead moves focus into the+button and continue with Tab, including from the **Move to** submenu. ArrowLeft+leaves the submenu and returns to **Move to** without closing the parent menu.+Choosing Rename instead moves focus into thedialog; clicking outside a menu keeps focus at the clicked destination.Drag a topic within its current sidebar group to keep frequently used work indiff --git a/webui/src/components/ChatList.tsx b/webui/src/components/ChatList.tsxindex 0c7a5e2ab..5bbeb60ba 100644--- a/webui/src/components/ChatList.tsx+++ b/webui/src/components/ChatList.tsx@@ -1,6 +1,8 @@import {+ createContext,memo,useCallback,+ useContext,useEffect,useLayoutEffect,useMemo,@@ -87,6 +89,8 @@ interface SidebarActionMenuController {openFromContextMenu: (event: ReactMouseEvent<HTMLElement>, id: string) => void;}+const SidebarActionMenuEscapeContext = createContext<(() => void) | undefined>(undefined);+function SidebarActionMenuContent({children,portalContainer,@@ -95,21 +99,24 @@ function SidebarActionMenuContent({portalContainer?: HTMLElement | null;}) {const restoreFocusOnEscape = useRef(false);+ const markEscape = () => { restoreFocusOnEscape.current = true; };return (- <DropdownMenuContent- align="end"- className={ACTION_MENU_CONTENT_CLASS}- portalContainer={portalContainer}- onEscapeKeyDown={() => { restoreFocusOnEscape.current = true; }}- onCloseAutoFocus={(event) => {- // Actions can open a dialog or remove the trigger. Only Escape returns- // to it; Radix still owns the trigger and outside-interaction handling.- if (!restoreFocusOnEscape.current) event.preventDefault();- restoreFocusOnEscape.current = false;- }}- >- {children}- </DropdownMenuContent>+ <SidebarActionMenuEscapeContext.Provider value={markEscape}>+ <DropdownMenuContent+ align="end"+ className={ACTION_MENU_CONTENT_CLASS}+ portalContainer={portalContainer}+ onEscapeKeyDown={markEscape}+ onCloseAutoFocus={(event) => {+ // Actions can open a dialog or remove the trigger. Only Escape returns+ // to it; Radix still owns the trigger and outside-interaction handling.+ if (!restoreFocusOnEscape.current) event.preventDefault();+ restoreFocusOnEscape.current = false;+ }}+ >+ {children}+ </DropdownMenuContent>+ </SidebarActionMenuEscapeContext.Provider>);}@@ -1617,6 +1624,8 @@ function MoveToGroupSubmenu({onMove: (targetKey: string) => void;}) {const { t } = useTranslation();+ // Radix sends Escape only to the topmost submenu before closing the root.+ const onEscapeKeyDown = useContext(SidebarActionMenuEscapeContext);if (targets.length === 0) return null;return (<DropdownMenuSub>@@ -1624,7 +1633,7 @@ function MoveToGroupSubmenu({<MoveRight className="h-4 w-4 shrink-0" aria-hidden />{t("workbench.moveTo")}</DropdownMenuSubTrigger>- <DropdownMenuSubContent>+ <DropdownMenuSubContent onEscapeKeyDown={onEscapeKeyDown}>{targets.map((target) => (<DropdownMenuItemkey={target.key}diff --git a/webui/src/tests/chat-list-focus.test.tsx b/webui/src/tests/chat-list-focus.test.tsxindex ee3a8eb91..b18343877 100644--- a/webui/src/tests/chat-list-focus.test.tsx+++ b/webui/src/tests/chat-list-focus.test.tsx@@ -1,5 +1,5 @@import { useState } from "react";-import { render, screen, waitFor } from "@testing-library/react";+import { act, render, screen, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";@@ -26,6 +26,10 @@ function SidebarFocusCase() {}]}activeKey={topic.key}paneGroups={{+ [topic.key]: {+ tabKey: "tab:review", title: "Review", activePaneKey: topic.key, visible: false,+ panes: [{ key: topic.key, chatId: topic.chatId, title: "Review" }],+ },"websocket:group": {tabKey: "websocket:group", title: "Group", activePaneKey: "websocket:group",panes: [@@ -38,6 +42,7 @@ function SidebarFocusCase() {onRequestDelete={vi.fn()}onTogglePin={vi.fn()}onToggleArchive={vi.fn()}+ onAttachPane={vi.fn()}onRequestRename={(_key, title) => setRename(title)}onRequestRenameTab={(_key, title) => setRename(title)}onRequestRenameProject={(_key, title) => setRename(title)}@@ -105,6 +110,40 @@ describe("sidebar action focus", () => {expect(outside).toHaveFocus();});+ it("returns Escape from Move to to the root action button", async () => {+ const user = userEvent.setup();+ render(<SidebarFocusCase />);+ const trigger = screen.getByRole("button", { name: "Topic actions for Review" });+ trigger.focus();+ await user.keyboard("{Enter}");+ const move = await screen.findByRole("menuitem", { name: "Move to", exact: true });+ act(() => move.focus());+ await user.keyboard("{ArrowRight}");+ await screen.findByRole("menuitem", { name: "Group · 2/4" });+ await user.keyboard("{Escape}");+ await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());+ await waitFor(() => expect(trigger).toHaveFocus());+ });++ it("keeps ArrowLeft within the parent menu, then hands Rename its input focus", async () => {+ const user = userEvent.setup();+ render(<SidebarFocusCase />);+ const trigger = screen.getByRole("button", { name: "Topic actions for Review" });+ trigger.focus();+ await user.keyboard("{Enter}");+ const move = await screen.findByRole("menuitem", { name: "Move to", exact: true });+ act(() => move.focus());+ await user.keyboard("{ArrowRight}");+ await screen.findByRole("menuitem", { name: "Group · 2/4" });+ await user.keyboard("{ArrowLeft}");+ await waitFor(() => expect(move).toHaveFocus());+ expect(screen.queryByRole("menuitem", { name: "Group · 2/4" })).not.toBeInTheDocument();+ await user.click(screen.getByRole("menuitem", { name: "Rename", exact: true }));+ const input = await screen.findByPlaceholderText("Topic name");+ await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());+ expect(input).toHaveFocus();+ });+it("allows Select to remove the trigger without restoring focus to it", async () => {const user = userEvent.setup();render(<SidebarFocusCase />);