From 565ef0759b443d62bf06e90c6c53b5878d93d757 Mon Sep 17 00:00:00 2001 From: roberttwang Date: Tue, 24 Nov 2026 01:04:23 +0800 Subject: [PATCH 1/2] fix(web): keep focus when reopening settings navigation Move focus to the collapse button before the reopen button hides, and stop hiding the collapsed sidebar with a delayed visibility transition. Keep a short retry for frames where the button cannot take focus yet. (cherry picked from commit 917b176cb3381dcb4e36c8a6a09f321c2e22fd9f) Co-Authored-By: Claude Code --- e2e/ui/03-workbench-settings.spec.mjs | 8 ++++++++ web/app.js | 17 +++++++++++------ web/app/navigation.css | 7 +------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/e2e/ui/03-workbench-settings.spec.mjs b/e2e/ui/03-workbench-settings.spec.mjs index 3d6604fd6..0412919e4 100644 --- a/e2e/ui/03-workbench-settings.spec.mjs +++ b/e2e/ui/03-workbench-settings.spec.mjs @@ -109,7 +109,15 @@ test('desktop settings navigation reopens on the current page', async ({ page }) await collapse.click(); await expect(page.locator('#settingsSidebar')).toHaveAttribute('aria-hidden', 'true'); await expect(expand).toBeFocused(); + await expand.evaluate(button => { + delete button.dataset.focusAfterClick; + button.addEventListener('click', () => { + button.dataset.focusAfterClick = document.activeElement?.id || ''; + }, { once: true }); + }); await expand.press('Enter'); + const focusAfterClick = await page.locator('#settingsSidebarExpand').getAttribute('data-focus-after-click'); + expect(focusAfterClick).toBe('settingsSidebarToggle'); await expect(collapse).toBeVisible(); await expect(collapse).toBeFocused(); await expect(page).toHaveURL(/#\/settings$/); diff --git a/web/app.js b/web/app.js index 65b21f734..68d70179c 100644 --- a/web/app.js +++ b/web/app.js @@ -1018,9 +1018,9 @@ function bind(){ $('#settingsSidebarToggle')?.addEventListener('click',()=>{cancelSettingsRouteTransition();setSettingsSidebarExpanded(!settingsSidebarExpanded())}); $('#settingsSidebarExpand')?.addEventListener('click',()=>{ cancelSettingsRouteTransition(); - setSettingsSidebarExpanded(true); - // Wait for the sidebar's descendants to inherit the restored visibility; reduced - // motion still runs a near-zero visibility transition, so retry for a few frames. + setSettingsSidebarExpanded(true,document.activeElement===document.body); + // Focus normally moves before the opener hides. If the toggle cannot take + // focus yet, focus falls back to the body; retry for a few frames. let frames=0; const focusToggle=()=>requestAnimationFrame(()=>{ if(!settingsSidebarExpanded()||document.activeElement!==document.body)return; @@ -1028,7 +1028,7 @@ function bind(){ toggle?.focus({preventScroll:true}); if(toggle&&document.activeElement!==toggle&&++frames<30)focusToggle(); }); - requestAnimationFrame(focusToggle); + if(document.activeElement!==$('#settingsSidebarToggle'))focusToggle(); }); document.addEventListener('click',event=>{ if(document.body.classList.contains('management-mode')&&event.target instanceof Element&&event.target.closest('.collab-rail-toggle')){ @@ -1775,7 +1775,7 @@ settingsRouteMotion.addEventListener('change',()=>{ if(pending)switchView(pending); setSettingsSidebarExpanded(settingsSidebarExpanded()); }); -function setSettingsSidebarExpanded(expanded){ +function setSettingsSidebarExpanded(expanded,focusToggle=false){ const managing=document.body.classList.contains('management-mode'); const open=managing&&expanded; const entering=managing&&!settingsSidebarWasManaged; @@ -1802,7 +1802,7 @@ function setSettingsSidebarExpanded(expanded){ toggle.title=open?'收起设置导航':'展开设置导航'; } const reopen=$('#settingsSidebarExpand'); - if(reopen)reopen.hidden=!managing||open; + if(reopen&&!open)reopen.hidden=!managing; const mobileToggle=$('.collab-rail-toggle'); if(mobileToggle){ mobileToggle.setAttribute('aria-expanded',String(open)); @@ -1819,6 +1819,11 @@ function setSettingsSidebarExpanded(expanded){ if(managing&&!open)sidebar.setAttribute('aria-hidden','true'); else sidebar.removeAttribute('aria-hidden'); } + if(reopen&&open){ + // Transfer focus before hiding the expand button. + if(focusToggle||document.activeElement===reopen)toggle?.focus({preventScroll:true}); + reopen.hidden=true; + } if(animateEntry){ // Keep the mounted panel at its closed geometry for one layout before reveal. settingsSidebarEntryFrame=requestAnimationFrame(()=>{ diff --git a/web/app/navigation.css b/web/app/navigation.css index 77618389e..d08fa6793 100644 --- a/web/app/navigation.css +++ b/web/app/navigation.css @@ -256,10 +256,7 @@ body.management-mode .platform-sidebar { width: var(--sidebar-w) !important; clip-path: inset(0 0 0 0 round 16px); opacity: 1; - visibility: visible; - transition: - clip-path var(--settings-sidebar-duration) var(--settings-sidebar-ease), - visibility 0s; + transition: clip-path var(--settings-sidebar-duration) var(--settings-sidebar-ease); } body.management-mode .shell-main { @@ -273,9 +270,7 @@ body.management-mode .app-shell::before { body.management-mode:is(.settings-sidebar-hidden, .settings-sidebar-entering) .platform-sidebar { clip-path: inset(0 100% 0 0 round 16px); - visibility: hidden; pointer-events: none; - transition-delay: 0s, var(--settings-sidebar-duration); } @media (prefers-reduced-motion: reduce) { From fd4b59552628d85333a8b95dc23591dbc61f1428 Mon Sep 17 00:00:00 2001 From: Robert0622 <53806540+Robert0622@users.noreply.github.com> Date: Wed, 25 Nov 2026 11:03:36 +0800 Subject: [PATCH 2/2] fix(web): keep settings navigation accessible on narrow screens --- e2e/ui/03-workbench-settings.spec.mjs | 26 ++++++++++++++++++++++++++ web/app/navigation.css | 6 ++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/e2e/ui/03-workbench-settings.spec.mjs b/e2e/ui/03-workbench-settings.spec.mjs index 0412919e4..fce87020c 100644 --- a/e2e/ui/03-workbench-settings.spec.mjs +++ b/e2e/ui/03-workbench-settings.spec.mjs @@ -148,6 +148,32 @@ test('desktop settings returns keyboard focus after the reopened button becomes await expect(collapse).toBeFocused(); }); +for (const width of [900, 480]) { + test(`settings navigation reopens and restores keyboard focus at ${width}px`, async ({ page }) => { + await page.setViewportSize({ width, height: 900 }); + await page.emulateMedia({ reducedMotion: 'reduce' }); + await openView(page, 'settings'); + + const sidebar = page.locator('#settingsSidebar'); + const collapse = page.locator('#settingsSidebarToggle'); + const expand = page.locator('#settingsSidebarExpand'); + if (await sidebar.getAttribute('aria-hidden') === 'true') { + await expect(expand).toBeVisible(); + await expand.press('Enter'); + } + + await collapse.press('Enter'); + await expect(sidebar).toHaveAttribute('aria-hidden', 'true'); + await expect(expand).toBeVisible(); + await expect(expand).toBeFocused(); + + await expand.press('Space'); + await expect(sidebar).not.toHaveAttribute('aria-hidden', 'true'); + await expect(collapse).toBeFocused(); + await expect(page).toHaveURL(/#\/settings$/); + }); +} + test('personal credentials: the add wizard validates, saves write-only, and the row clears it', async ({ page, identity }) => { const me = identity.user; test.skip(!!(await userById(me.id))?.codexApiKeyConfigured, 'the token owner already has a Codex API Key; not overwriting a real credential'); diff --git a/web/app/navigation.css b/web/app/navigation.css index d08fa6793..19c0a4b69 100644 --- a/web/app/navigation.css +++ b/web/app/navigation.css @@ -99,10 +99,8 @@ body.management-mode .platform-sidebar > .settings-navigation-header { display: none; } -@media (max-width: 1000px) { - .settings-navigation-reopen { - display: none; - } +.settings-navigation-reopen { + flex-shrink: 0; } .platform-sidebar nav {