Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): stabilize modal dismissal and picker focus
chengyongru56052ff58385
diff --git a/webui/src/components/thread/WorkspaceControls.tsx b/webui/src/components/thread/WorkspaceControls.tsxindex 7b9bde031..79609ceb7 100644--- a/webui/src/components/thread/WorkspaceControls.tsx+++ b/webui/src/components/thread/WorkspaceControls.tsx@@ -211,6 +211,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,const completionRequest = useRef(0);const triggerRef = useRef<HTMLButtonElement>(null);const [keyboardInteraction, setKeyboardInteraction] = useState(false);+ const openedWithKeyboard = useRef(false);const inputRef = useRef<HTMLInputElement>(null);const confirmRef = useRef<HTMLButtonElement>(null);const optionsId = useId();@@ -562,7 +563,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,<Dialog open={open} onOpenChange={setOpen}><WorkspacePickerTooltip label={`${t("workspace.picker.switchDirectory")}\n${displayedScope?.project_path ?? ""}`}><DialogTrigger asChild>- <button ref={triggerRef} onPointerDown={() => setKeyboardInteraction(false)} onKeyDown={() => setKeyboardInteraction(true)} type="button" disabled={disabled} aria-label={t("workspace.picker.switchDirectory")} className="thread-composer-workspace touch-target inline-flex h-8 min-w-0 max-w-full items-center gap-1.5 rounded-control px-2 text-[12px] font-medium text-muted-foreground outline-none transition-colors hover:bg-foreground/[0.055] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-55">+ <button ref={triggerRef} onClick={event => { openedWithKeyboard.current = event.detail === 0; }} onPointerDown={() => setKeyboardInteraction(false)} onKeyDown={() => setKeyboardInteraction(true)} type="button" disabled={disabled} aria-label={t("workspace.picker.switchDirectory")} className="thread-composer-workspace touch-target inline-flex h-8 min-w-0 max-w-full items-center gap-1.5 rounded-control px-2 text-[12px] font-medium text-muted-foreground outline-none transition-colors hover:bg-foreground/[0.055] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-55"><WorkspaceIcon className="h-3.5 w-3.5 shrink-0" /><span className="min-w-0 truncate">{projectLabel}</span></button>@@ -580,7 +581,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,else if (event.altKey && event.key === "ArrowUp" && parentPath) { event.preventDefault(); navigate(parentPath); }}}onEscapeKeyDown={event => { if (editingPath) { event.preventDefault(); cancelPathEditing(); } }}- onCloseAutoFocus={event => { if (!keyboardInteraction) event.preventDefault(); }}>+ onCloseAutoFocus={event => { if (!openedWithKeyboard.current) event.preventDefault(); }}><DialogTitle className="sr-only">{t("workspace.picker.title")}</DialogTitle><DialogDescription className="sr-only">{t("workspace.picker.description")}</DialogDescription><div className="flex shrink-0 items-center gap-1 bg-muted px-[var(--picker-toolbar-inset)] pt-[var(--picker-toolbar-inset)] pb-3">diff --git a/webui/src/components/ui/floating-surface.ts b/webui/src/components/ui/floating-surface.tsindex d16c528eb..a28fcde1a 100644--- a/webui/src/components/ui/floating-surface.ts+++ b/webui/src/components/ui/floating-surface.ts@@ -4,8 +4,10 @@ export const floatingSurfaceElevationClassName =export const floatingSurfaceVisualClassName =`rounded-floating p-1.5 ${floatingSurfaceElevationClassName}`;+// A content-owned exit can keep the overlay mounted after its fade finishes.+// Retain the transparent final frame until the modal's presence unmounts it.export const modalOverlayClassName =- "fixed inset-0 z-50 bg-black/25 backdrop-blur-[8px] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0";+ "fixed inset-0 z-50 bg-black/25 backdrop-blur-[8px] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:fill-mode-forwards data-[state=open]:fade-in-0";export const modalSurfaceClassName ="bg-background text-foreground shadow-[0_12px_36px_rgba(15,23,42,0.12)] dark:bg-popover dark:shadow-[0_18px_44px_rgba(0,0,0,0.32)]";diff --git a/webui/src/tests/workspace-picker.test.tsx b/webui/src/tests/workspace-picker.test.tsxindex 3a4e2255d..816b2f129 100644--- a/webui/src/tests/workspace-picker.test.tsx+++ b/webui/src/tests/workspace-picker.test.tsx@@ -21,6 +21,26 @@ const directory: WorkspaceDirectoriesPayload = {};describe("Workspace project picker", () => {+ it.each(["pointer", "keyboard"])("restores the opening focus context after %s entry and Escape", async (entry) => {+ const user = userEvent.setup();+ const onChange = vi.fn();+ render(<WorkspaceProjectPicker isHero scope={scope} defaultScope={scope} controls={catalog.controls} onBrowseDirectories={vi.fn().mockResolvedValue(directory)} onChange={onChange} />);+ const trigger = screen.getByRole("button", { name: "Switch working directory" });+ if (entry === "pointer") await user.click(trigger);+ else {+ act(() => trigger.focus());+ await user.keyboard("{Enter}");+ }+ await screen.findByRole("option", { name: "/srv/workspace/alpha" });+ await user.keyboard("{Escape}");+ await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());+ // FocusScope restores focus in a task after its exit cleanup.+ await act(() => new Promise(resolve => setTimeout(resolve, 0)));+ if (entry === "keyboard") expect(trigger).toHaveFocus();+ else expect(trigger).not.toHaveFocus();+ expect(onChange).not.toHaveBeenCalled();+ });+it.each([["/srv/中文 项目/src", ["/", "/srv", "/srv/中文 项目", "/srv/中文 项目/src"]],["C:\\Projects\\alpha", ["C:\\", "C:\\Projects", "C:\\Projects\\alpha"]],