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 menu focus on Escape
Xubin Ren3e3d8e3d7695
diff --git a/docs/webui.md b/docs/webui.mdindex cc78c439d..8ccf02bc1 100644--- a/docs/webui.md+++ b/docs/webui.md@@ -114,7 +114,9 @@ without changing the original thread.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 on-hover or keyboard focus.+hover 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+dialog; clicking outside a menu keeps focus at the clicked destination.Drag a topic within its current sidebar group to keep frequently used work inyour preferred order. Drag a topic from the sidebar into the composer when youdiff --git a/webui/src/components/ChatList.tsx b/webui/src/components/ChatList.tsxindex 77b0a6a56..0c7a5e2ab 100644--- a/webui/src/components/ChatList.tsx+++ b/webui/src/components/ChatList.tsx@@ -7,7 +7,7 @@ import {useRef,useState,} from "react";-import type { CSSProperties, MouseEvent as ReactMouseEvent, ReactElement } from "react";+import type { CSSProperties, MouseEvent as ReactMouseEvent, ReactElement, ReactNode } from "react";import {Archive,ArchiveRestore,@@ -87,6 +87,32 @@ interface SidebarActionMenuController {openFromContextMenu: (event: ReactMouseEvent<HTMLElement>, id: string) => void;}+function SidebarActionMenuContent({+ children,+ portalContainer,+}: {+ children: ReactNode;+ portalContainer?: HTMLElement | null;+}) {+ const restoreFocusOnEscape = useRef(false);+ 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>+ );+}+function SidebarItemTooltip({label,children,@@ -1056,11 +1082,8 @@ export const ChatList = memo(function ChatList({><MoreHorizontal className="h-3.5 w-3.5" /></DropdownMenuTrigger>- <DropdownMenuContent- align="end"- className={ACTION_MENU_CONTENT_CLASS}+ <SidebarActionMenuContentportalContainer={actionMenuPortalContainer}- onCloseAutoFocus={(event) => event.preventDefault()}><DropdownMenuItem onSelect={() => onTogglePin(s.key)}>{isPinned ? (@@ -1113,7 +1136,7 @@ export const ChatList = memo(function ChatList({<Trash2 className="h-4 w-4 shrink-0" />{t("chat.delete")}</DropdownMenuItem>- </DropdownMenuContent>+ </SidebarActionMenuContent></DropdownMenu>) : null}</div>@@ -1304,11 +1327,8 @@ function WorkbenchTabHeader({><MoreHorizontal className="h-3.5 w-3.5" /></DropdownMenuTrigger>- <DropdownMenuContent- align="end"- className={ACTION_MENU_CONTENT_CLASS}+ <SidebarActionMenuContentportalContainer={actionMenuPortalContainer}- onCloseAutoFocus={(event) => event.preventDefault()}>{onRequestRename ? (<DropdownMenuItem onSelect={onRequestRename}>@@ -1330,7 +1350,7 @@ function WorkbenchTabHeader({<Trash2 className="h-4 w-4 shrink-0" />{t("workbench.deleteConversations")}</DropdownMenuItem>- </DropdownMenuContent>+ </SidebarActionMenuContent></DropdownMenu></>@@ -1499,11 +1519,8 @@ function ActivePaneRows({><MoreHorizontal className="h-3.5 w-3.5" /></DropdownMenuTrigger>- <DropdownMenuContent- align="end"- className={ACTION_MENU_CONTENT_CLASS}+ <SidebarActionMenuContentportalContainer={actionMenuPortalContainer}- onCloseAutoFocus={(event) => event.preventDefault()}><DropdownMenuItem onSelect={() => onTogglePin(pane.key)}>{isPinned ? (@@ -1554,7 +1571,7 @@ function ActivePaneRows({<Trash2 className="h-4 w-4 shrink-0" />{t("chat.delete")}</DropdownMenuItem>- </DropdownMenuContent>+ </SidebarActionMenuContent></DropdownMenu> : null}</div></li>@@ -1796,11 +1813,8 @@ function ProjectGroupHeader({><MoreHorizontal className="h-3.5 w-3.5" /></DropdownMenuTrigger>- <DropdownMenuContent- align="end"- className={ACTION_MENU_CONTENT_CLASS}+ <SidebarActionMenuContentportalContainer={actionMenuPortalContainer}- onCloseAutoFocus={(event) => event.preventDefault()}>{onNewChat ? (<DropdownMenuItem onSelect={onNewChat}>@@ -1814,7 +1828,7 @@ function ProjectGroupHeader({{t("chat.rename")}</DropdownMenuItem>) : null}- </DropdownMenuContent>+ </SidebarActionMenuContent></DropdownMenu>) : null}diff --git a/webui/src/tests/chat-list-focus.test.tsx b/webui/src/tests/chat-list-focus.test.tsxnew file mode 100644index 000000000..ee3a8eb91--- /dev/null+++ b/webui/src/tests/chat-list-focus.test.tsx@@ -0,0 +1,120 @@+import { useState } from "react";+import { render, screen, waitFor } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++import { ChatList } from "@/components/ChatList";+import { RenameChatDialog } from "@/components/RenameChatDialog";+import type { ChatSummary } from "@/lib/types";+import { mockBrowserFocus } from "./browser-focus";++const topic: ChatSummary = {+ key: "websocket:review", chatId: "review", channel: "websocket",+ title: "Review", preview: "", createdAt: "2026-10-04T10:00:00Z",+ updatedAt: "2026-10-04T10:00:00Z",+};++function SidebarFocusCase() {+ const [rename, setRename] = useState<string | null>(null);+ return <>+ <ChatList+ sessions={[topic, {+ ...topic, key: "websocket:group", chatId: "group", title: "Group",+ }, {+ ...topic, key: "websocket:project", chatId: "project", title: "Project task",+ workspaceScope: { project_path: "/workspace/photos", project_name: "Photos", access_mode: "restricted" },+ }]}+ activeKey={topic.key}+ paneGroups={{+ "websocket:group": {+ tabKey: "websocket:group", title: "Group", activePaneKey: "websocket:group",+ panes: [+ { key: "websocket:group", chatId: "group", title: "Group" },+ { key: "websocket:research", chatId: "research", title: "Research" },+ ],+ },+ }}+ onSelect={vi.fn()}+ onRequestDelete={vi.fn()}+ onTogglePin={vi.fn()}+ onToggleArchive={vi.fn()}+ onRequestRename={(_key, title) => setRename(title)}+ onRequestRenameTab={(_key, title) => setRename(title)}+ onRequestRenameProject={(_key, title) => setRename(title)}+ />+ <button>Outside destination</button>+ <RenameChatDialog open={rename !== null} title={rename ?? ""}+ onCancel={() => setRename(null)} onConfirm={() => setRename(null)} />+ </>;+}++describe("sidebar action focus", () => {+ let restoreBrowserFocus: () => void;+ beforeEach(() => { restoreBrowserFocus = mockBrowserFocus(); });+ afterEach(() => {+ restoreBrowserFocus();+ localStorage.removeItem("nanobot-webui.collapsed-pane-groups.v1");+ });++ it.each([+ "Topic actions for Review",+ "Topic actions for Group",+ "Research pane actions",+ "Topic actions for Photos",+ ])("returns Escape focus to %s and allows continued tabbing", async (name) => {+ const user = userEvent.setup();+ render(<SidebarFocusCase />);+ const trigger = screen.getByRole("button", { name, exact: true });+ trigger.focus();+ await user.keyboard("{Enter}");+ await screen.findByRole("menu");+ await user.keyboard("{Escape}");+ await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());+ await waitFor(() => expect(trigger).toHaveFocus());+ await user.tab();+ expect(trigger).not.toHaveFocus();+ expect(document.body).not.toHaveFocus();+ });++ it("does not reuse Escape focus restoration when the next action opens Rename", async () => {+ const user = userEvent.setup();+ render(<SidebarFocusCase />);+ const trigger = screen.getByRole("button", { name: "Topic actions for Review" });+ trigger.focus();+ await user.keyboard("{Enter}{Escape}");+ await waitFor(() => expect(trigger).toHaveFocus());+ await user.keyboard("{Enter}");+ await user.click(await screen.findByRole("menuitem", { name: "Rename", exact: true }));+ const input = await screen.findByPlaceholderText("Topic name");+ await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());+ await waitFor(() => expect(input).toHaveFocus());+ await user.keyboard("Updated");+ expect(input).toHaveValue("ReviewUpdated");+ });++ it("keeps an outside click focused on its destination", async () => {+ const user = userEvent.setup();+ render(<SidebarFocusCase />);+ const trigger = screen.getByRole("button", { name: "Topic actions for Review" });+ trigger.focus();+ await user.keyboard("{Enter}");+ await screen.findByRole("menu");+ const outside = screen.getByRole("button", { name: "Outside destination" });+ await user.click(outside);+ await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());+ expect(outside).toHaveFocus();+ });++ it("allows Select to remove the trigger without restoring focus to it", async () => {+ const user = userEvent.setup();+ render(<SidebarFocusCase />);+ const trigger = screen.getByRole("button", { name: "Topic actions for Review" });+ trigger.focus();+ await user.keyboard("{Enter}");+ await user.click(await screen.findByRole("menuitem", { name: "Select", exact: true }));+ await waitFor(() => expect(trigger).not.toBeInTheDocument());+ expect(trigger).not.toHaveFocus();+ await user.keyboard("{Escape}");+ expect(screen.getByRole("button", { name: "Topic actions for Review" })).toBeInTheDocument();+ });+});