fix(settings): let modal restore preset guide focus

This commit is contained in:
Xinyu Yang committed 2026-09-23 17:21:45 +08:00
1 parent 1aebb43147
commit cec4e70f8d
2 files changed
+6 -7

No files matched your search

@@ -95,11 +95,7 @@ export function PresetGuideDialog({ guide, initialPage, t, onClose }: {
const content = useRef<HTMLDivElement>(null)
useLayoutEffect(() => {
const previous = document.activeElement
content.current?.querySelector<HTMLButtonElement>('[role="tab"][aria-selected="true"]')?.focus()
return () => {
if (previous instanceof HTMLElement) previous.focus()
}
}, [])
// This reader sits above Settings. Keep keyboard navigation in the reader,
@@ -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', () => {