fix(web): restore settings focus after commit

This commit is contained in:
Yichen Jiang committed 2026-08-19 15:40:49 +08:00
1 parent c2a6f67e22
commit 3f5fc12b4c
1 file changed
+6 -2
@@ -107,12 +107,16 @@ export function SettingsRoot(props: SettingsRootComponentProps) {
const [activeId, setActiveId] = useState<string | undefined>(undefined)
const [completedOnboarding, setCompletedOnboarding] = useState<ReadonlySet<string>>(() => new Set())
const triggerButton = useRef<HTMLButtonElement | null>(null)
const wasOpen = useRef(open)
const close = useCallback(() => {
setOpen(false)
setActiveId(undefined)
// Defer until React flushes the close state so panel unmount cannot steal focus; an unmounted root clears the ref.
queueMicrotask(() => { triggerButton.current?.focus() })
}, [])
// Restore after the close commit, when the dialog can no longer own focus.
useEffect(() => {
if (wasOpen.current && !open) triggerButton.current?.focus()
wasOpen.current = open
}, [open])
const openSection = useCallback((id: string) => {
setActiveId(id)
setOpen(true)