diff --git a/webui/browser/sidebar-activity-fixture.tsx b/webui/browser/sidebar-activity-fixture.tsx index d9355b713..8b600a611 100644 --- a/webui/browser/sidebar-activity-fixture.tsx +++ b/webui/browser/sidebar-activity-fixture.tsx @@ -17,13 +17,16 @@ export function SidebarActivityFixture() { const [count, setCount] = useState(new URLSearchParams(location.search).has("all") ? sessions.length : 1); const [visible, setVisible] = useState(true); const [activeKey, setActiveKey] = useState(sessions[0].key); + const [titleOverrides, setTitleOverrides] = useState>({}); return
{visible && session.chatId)} sort="title_asc" onRequestDelete={() => {}} onTogglePin={() => {}} - onRequestRename={async () => {}} onToggleArchive={() => {}} + titleOverrides={titleOverrides} + onRequestRename={async (key, title) => setTitleOverrides(current => ({ ...current, [key]: title }))} + onToggleArchive={() => {}} />}
diff --git a/webui/browser/sidebar-rename.spec.ts b/webui/browser/sidebar-rename.spec.ts new file mode 100644 index 000000000..3bb7bbaf2 --- /dev/null +++ b/webui/browser/sidebar-rename.spec.ts @@ -0,0 +1,26 @@ +import { expect, test } from "@playwright/test"; + +for (const method of ["Enter", "Save button"] as const) { + test(`saving a topic name with ${method} restores appropriate sidebar focus`, async ({ page }) => { + await page.goto("/browser/fixture.html?case=sidebar-activity"); + const sidebar = page.getByRole("region", { name: "Activity sidebar" }); + const activeTopic = sidebar.getByRole("button", { name: "@bate Review history", exact: true }); + await sidebar.getByRole("button", { name: "Topic actions for Locate messages" }).click(); + await page.getByRole("menuitem", { name: "Rename" }).click(); + const input = sidebar.getByRole("textbox", { name: "Topic name" }); + await expect(input).toBeFocused(); + await input.fill("Renamed topic"); + + if (method === "Enter") await input.press("Enter"); + else await sidebar.getByRole("button", { name: "Save", exact: true }).click(); + + const renamedTopic = sidebar.getByRole("button", { name: "@jaru Renamed topic", exact: true }); + await expect(renamedTopic).toBeFocused(); + await expect(activeTopic).toHaveAttribute("aria-current", "page"); + await expect(renamedTopic).toHaveCSS("outline-style", method === "Enter" ? "solid" : "none"); + if (method === "Enter") { + await page.keyboard.press("Tab"); + await expect(sidebar.getByRole("button", { name: "Topic actions for Renamed topic" })).toBeFocused(); + } + }); +} diff --git a/webui/src/components/ChatList.tsx b/webui/src/components/ChatList.tsx index 2e975fbd3..1a80785d9 100644 --- a/webui/src/components/ChatList.tsx +++ b/webui/src/components/ChatList.tsx @@ -80,6 +80,7 @@ import type { ChatSummary, SidebarDensity, SidebarSortMode } from "@/lib/types"; const INITIAL_VISIBLE_SESSIONS = 160; const VISIBLE_SESSIONS_INCREMENT = 160; const ACTION_MENU_CONTENT_CLASS = "w-[11rem] min-w-[11rem] whitespace-nowrap"; +const TOPIC_BUTTON_FOCUS_CLASS = "rounded-md focus-visible:outline focus-visible:outline-1 focus-visible:-outline-offset-1 focus-visible:outline-sidebar-muted-foreground"; const COLLAPSED_PANE_GROUPS_STORAGE_KEY = "nanobot-webui.collapsed-pane-groups.v1"; const DETACH_PANE_DROP_TARGET = "__sidebar-standalone__"; @@ -1071,6 +1072,7 @@ export const ChatList = memo(function ChatList({ aria-pressed={deleteSelectionMode ? tabSelected : undefined} className={cn( "flex min-w-0 flex-1 items-center gap-2 overflow-hidden text-left", + TOPIC_BUTTON_FOCUS_CLASS, canDragSession && "cursor-grab active:cursor-grabbing", deleteSelectionMode && "cursor-default", compact ? "py-1" : "py-1.5", @@ -1553,6 +1555,7 @@ function ActivePaneRows({ aria-pressed={deleteSelectionMode ? selected : undefined} className={cn( "flex min-w-0 flex-1 items-center gap-2 overflow-hidden text-left font-normal leading-5", + TOPIC_BUTTON_FOCUS_CLASS, canDragSession && "cursor-grab active:cursor-grabbing", compact ? "py-1" : "py-1.5", deleteSelectionMode && "cursor-default",