Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
studio: restore focus to opener when settings dialog closes (#5612)
Daniel Hancf53ff68616b
diff --git a/studio/frontend/src/features/settings/settings-dialog.tsx b/studio/frontend/src/features/settings/settings-dialog.tsxindex e52257735e2..384e359f313 100644--- a/studio/frontend/src/features/settings/settings-dialog.tsx+++ b/studio/frontend/src/features/settings/settings-dialog.tsx@@ -74,6 +74,7 @@ export function SettingsDialog() {const activeTab = useSettingsDialogStore((s) => s.activeTab);const setActiveTab = useSettingsDialogStore((s) => s.setActiveTab);const closeDialog = useSettingsDialogStore((s) => s.closeDialog);+ const opener = useSettingsDialogStore((s) => s.opener);const reduced = useReducedMotion();const tabButtonRefs = useRef<Record<SettingsTab, HTMLButtonElement | null>>({general: null,@@ -98,6 +99,15 @@ export function SettingsDialog() {<DialogContentshowCloseButton={false}overlayClassName="bg-background/40"+ onCloseAutoFocus={(e) => {+ // Restore focus to the element that triggered openDialog().+ // Radix's FocusScope races our rAF-scheduled tab-button focus+ // and loses the previous-focus reference, so we restore by hand.+ if (opener && opener.isConnected) {+ e.preventDefault();+ opener.focus({ preventScroll: true });+ }+ }}className={cn("!max-w-none h-[560px] w-[820px] p-0 overflow-hidden","shadow-border rounded-xl border-border",diff --git a/studio/frontend/src/features/settings/stores/settings-dialog-store.ts b/studio/frontend/src/features/settings/stores/settings-dialog-store.tsindex a2e32f26a3a..7ac5422ff12 100644--- a/studio/frontend/src/features/settings/stores/settings-dialog-store.ts+++ b/studio/frontend/src/features/settings/stores/settings-dialog-store.ts@@ -15,6 +15,11 @@ export type SettingsTab =interface SettingsDialogState {open: boolean;activeTab: SettingsTab;+ // Element focused at the moment openDialog() ran. Radix's FocusScope+ // would normally track this, but the rAF-scheduled focus() in+ // settings-dialog.tsx races its previous-focus capture, leaving focus+ // on <body> after close. We restore explicitly via onCloseAutoFocus.+ opener: HTMLElement | null;openDialog: (tab?: SettingsTab) => void;closeDialog: () => void;setActiveTab: (tab: SettingsTab) => void;@@ -47,11 +52,21 @@ function loadInitialTab(): SettingsTab {export const useSettingsDialogStore = create<SettingsDialogState>((set) => ({open: false,activeTab: loadInitialTab(),+ opener: null,openDialog: (tab) =>set((state) => ({open: true,activeTab: tab ?? state.activeTab,+ opener:+ typeof document !== "undefined" &&+ document.activeElement instanceof HTMLElement &&+ document.activeElement !== document.body+ ? document.activeElement+ : null,})),+ // Do NOT clear `opener` here. onCloseAutoFocus runs on the next render+ // pass after `open: false` lands, so the opener must still be readable+ // from the store at that point. The next openDialog() overwrites it.closeDialog: () => set({ open: false }),setActiveTab: (tab) => {try {