From cec4e70f8d4dd42529ab445d5e3e22d0e2e4ac0d Mon Sep 17 00:00:00 2001 From: Xinyu Yang Date: Wed, 23 Sep 2026 17:21:45 +0800 Subject: [PATCH] fix(settings): let modal restore preset guide focus --- .../ui-agent-preset/src/client/PresetGuideDialog.tsx | 4 ---- .../client/ui-agent-preset/tests/section.client.spec.tsx | 9 ++++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/client/ui-agent-preset/src/client/PresetGuideDialog.tsx b/packages/client/ui-agent-preset/src/client/PresetGuideDialog.tsx index 310d397dbc..2811594e13 100644 --- a/packages/client/ui-agent-preset/src/client/PresetGuideDialog.tsx +++ b/packages/client/ui-agent-preset/src/client/PresetGuideDialog.tsx @@ -95,11 +95,7 @@ export function PresetGuideDialog({ guide, initialPage, t, onClose }: { const content = useRef(null) useLayoutEffect(() => { - const previous = document.activeElement content.current?.querySelector('[role="tab"][aria-selected="true"]')?.focus() - return () => { - if (previous instanceof HTMLElement) previous.focus() - } }, []) // This reader sits above Settings. Keep keyboard navigation in the reader, diff --git a/packages/client/ui-agent-preset/tests/section.client.spec.tsx b/packages/client/ui-agent-preset/tests/section.client.spec.tsx index 2d098700bf..2da128ce30 100644 --- a/packages/client/ui-agent-preset/tests/section.client.spec.tsx +++ b/packages/client/ui-agent-preset/tests/section.client.spec.tsx @@ -181,11 +181,12 @@ it.each([ expect(actions.makeDefault).not.toHaveBeenCalled() }) it('keeps keyboard focus in help and dismisses only the reader on Escape', () => { - const actions = view() + const closeSettings = vi.fn() + const actions = view({}, undefined, true, closeSettings) const trigger = within(rowFor('standard')).getByRole('button', { name: `${en.modeExplanation}: ${en.presetStandardName}` }) trigger.focus() fireEvent.click(trigger) - const dialog = screen.getByRole('dialog') + const dialog = screen.getByRole('dialog', { name: en.presetStandardName }) const details = within(dialog).getByRole('tab', { name: en.modeExplanation }) const panel = within(dialog).getByRole('tabpanel', { name: en.modeExplanation }) const close = within(dialog).getByRole('button', { name: en.close }) @@ -197,8 +198,10 @@ it('keeps keyboard focus in help and dismisses only the reader on Escape', () => fireEvent.keyDown(close, { key: 'Tab', shiftKey: true }) expect(document.activeElement).toBe(panel) fireEvent.keyDown(panel, { key: 'Escape' }) - expect(screen.queryByRole('dialog')).toBeNull() + expect(screen.queryByRole('dialog', { name: en.presetStandardName })).toBeNull() + expect(screen.getByRole('dialog', { name: 'Settings' })).toBeTruthy() expect(document.activeElement).toBe(trigger) + expect(closeSettings).not.toHaveBeenCalled() expect(actions.close).not.toHaveBeenCalled() }) it('connects keyboard selection to the visible guide panel', () => {