Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions e2e/ui/03-workbench-settings.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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$/);
Expand Down Expand Up @@ -140,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');
Expand Down
17 changes: 11 additions & 6 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1018,17 +1018,17 @@ 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;
const toggle=$('#settingsSidebarToggle');
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')){
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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(()=>{
Expand Down
13 changes: 3 additions & 10 deletions web/app/navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -256,10 +254,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 {
Expand All @@ -273,9 +268,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) {
Expand Down
Loading