Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(ui): restore modal focus lifecycle (#2935)
Call White1e4dc9a3e081
diff --git a/ui/src/components/steps/UserList.tsx b/ui/src/components/steps/UserList.tsxindex a2d66f93b..e2ec1b4b7 100644--- a/ui/src/components/steps/UserList.tsx+++ b/ui/src/components/steps/UserList.tsx@@ -13,7 +13,6 @@ import {RefreshCw,Shield,Trash2,- X,} from 'lucide-react';import { useTranslation } from 'react-i18next';import clsx from 'clsx';@@ -27,6 +26,7 @@ import { PlatformIcon } from '../visual';import { RoutingConfigPanel } from '../shared/RoutingConfigPanel';import { SearchField, ToggleSwitch } from '../settings/SettingsPrimitives';import { Button } from '../ui/button';+import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';import { Input } from '../ui/input';interface UserConfig {@@ -418,31 +418,20 @@ const ActiveCodeBox: React.FC<{};const Modal: React.FC<{ title: string; onClose: () => void; children: React.ReactNode }> = ({ title, onClose, children }) => (- <div- className="fixed inset-0 z-50 flex items-center justify-center overflow-y-auto bg-black/40 px-4 py-4"- role="dialog"- aria-modal="true"- aria-label={title}- onClick={onClose}- >- <div- className="flex min-w-0 max-h-[calc(100dvh-2rem)] w-full max-w-2xl flex-col overflow-y-auto rounded-2xl border border-border bg-surface-2 shadow-[0_42px_80px_-42px_rgba(0,0,0,0.85)]"- onClick={(e) => e.stopPropagation()}+ <Dialog open onOpenChange={(next) => { if (!next) onClose(); }}>+ <DialogContent+ aria-describedby={undefined}+ closeLabel={title}+ className="flex min-w-0 max-h-[calc(100dvh-2rem)] w-full max-w-2xl flex-col overflow-y-auto rounded-2xl border border-border bg-surface-2 p-0 shadow-[0_42px_80px_-42px_rgba(0,0,0,0.85)]"><div className="flex min-w-0 items-center justify-between gap-3 border-b border-border px-4 py-3">- <h4 className="min-w-0 flex-1 break-words text-base font-semibold text-foreground [overflow-wrap:anywhere]">{title}</h4>- <button- type="button"- onClick={onClose}- className="rounded text-muted transition-colors hover:text-foreground"- title={title}- >- <X size={16} />- </button>+ <DialogTitle className="min-w-0 flex-1 break-words text-base font-semibold text-foreground [overflow-wrap:anywhere]">+ {title}+ </DialogTitle></div>{children}- </div>- </div>+ </DialogContent>+ </Dialog>);// ─── User List Page ──────────────────────────────────────────────────────diff --git a/ui/src/components/ui/dialog.test.tsx b/ui/src/components/ui/dialog.test.tsxindex d42156140..bf6a067ff 100644--- a/ui/src/components/ui/dialog.test.tsx+++ b/ui/src/components/ui/dialog.test.tsx@@ -1,13 +1,85 @@/* @vitest-environment jsdom */-import { act, cleanup, render, screen } from '@testing-library/react';+import { act, cleanup, render, screen, waitFor } from '@testing-library/react';+import userEvent from '@testing-library/user-event';import { afterEach, describe, expect, it, vi } from 'vitest';+import { useState } from 'react';import { RouteSurfaceActiveContext } from '../../lib/routeSurfaceActivity';import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from './dialog';afterEach(cleanup);+describe('DialogContent focus lifecycle', () => {+ it('restores focus to an underlying opener when a nested dialog closes', async () => {+ const user = userEvent.setup();+ const Harness = () => {+ const [parentOpen, setParentOpen] = useState(false);+ const [childOpen, setChildOpen] = useState(false);+ return (+ <>+ <button type="button" onClick={() => setParentOpen(true)}>open-parent</button>+ <Dialog open={parentOpen} onOpenChange={setParentOpen}>+ <DialogContent aria-describedby={undefined}>+ <DialogTitle>Parent</DialogTitle>+ <button type="button" onClick={() => setChildOpen(true)}>open-child</button>+ </DialogContent>+ </Dialog>+ <Dialog open={childOpen} onOpenChange={setChildOpen}>+ <DialogContent aria-describedby={undefined}>+ <DialogTitle>Child</DialogTitle>+ </DialogContent>+ </Dialog>+ </>+ );+ };++ render(<Harness />);+ await user.click(screen.getByRole('button', { name: 'open-parent' }));+ const childTrigger = screen.getByRole('button', { name: 'open-child' });+ await user.click(childTrigger);+ await user.keyboard('{Escape}');++ await waitFor(() => expect(screen.queryByRole('heading', { name: 'Child' })).toBeNull());+ expect(document.activeElement).toBe(childTrigger);+ });++ it('leaves focus with a replacement nested dialog', async () => {+ const user = userEvent.setup();+ const Harness = () => {+ const [childOpen, setChildOpen] = useState(false);+ const [replacementOpen, setReplacementOpen] = useState(false);+ return (+ <>+ <button type="button" onClick={() => setChildOpen(true)}>open-child</button>+ <Dialog open={childOpen} onOpenChange={(next) => {+ setChildOpen(next);+ if (!next) setReplacementOpen(true);+ }}>+ <DialogContent aria-describedby={undefined}>+ <DialogTitle>Child</DialogTitle>+ </DialogContent>+ </Dialog>+ <Dialog open={replacementOpen} onOpenChange={setReplacementOpen}>+ <DialogContent aria-describedby={undefined}>+ <DialogTitle>Replacement</DialogTitle>+ <button type="button">replacement-action</button>+ </DialogContent>+ </Dialog>+ </>+ );+ };++ render(<Harness />);+ const childTrigger = screen.getByRole('button', { name: 'open-child' });+ await user.click(childTrigger);+ await user.keyboard('{Escape}');++ const replacement = await screen.findByRole('dialog', { name: 'Replacement' });+ expect(replacement.contains(document.activeElement)).toBe(true);+ });+});+describe('DialogContent layout safety', () => {it('wraps long unbroken titles without letting modal controls overflow', () => {const title = 'Delete AVIBE_UI_REGRESSION_STANDARD_20260810_1234567890_abcdefghijklmnopqrstuvwxyz';diff --git a/ui/src/components/ui/dialog.tsx b/ui/src/components/ui/dialog.tsxindex 1c85fb69e..4f3e042c0 100644--- a/ui/src/components/ui/dialog.tsx+++ b/ui/src/components/ui/dialog.tsx@@ -39,6 +39,7 @@ export const DialogContent = React.forwardRef<>(({ className, children, mobileSheetHeight = 'content', closeLabel = 'Close', onCloseAutoFocus, ...props }, ref) => {const active = useRouteSurfaceActive();const activeRef = useLatestRef(active);+ const previousFocusRef = React.useRef<HTMLElement | null>(null);if (!active) return null;return (<DialogPortal>@@ -57,11 +58,32 @@ export const DialogContent = React.forwardRef<className)}{...props}+ onOpenAutoFocus={(event) => {+ previousFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;+ props.onOpenAutoFocus?.(event);+ }}onCloseAutoFocus={(event) => {// Suspension is not a user close. Do not run owner close effects or// return focus into the inactive surface from Radix's delayed cleanup.- if (!activeRef.current) event.preventDefault();- else onCloseAutoFocus?.(event);+ if (!activeRef.current) {+ event.preventDefault();+ return;+ }+ onCloseAutoFocus?.(event);+ if (event.defaultPrevented) return;+ event.preventDefault();+ const previousFocus = previousFocusRef.current;+ if (!previousFocus?.isConnected) return;+ // A nested dialog may replace this one in the same React commit. If+ // the replacement already owns focus, leave it alone; otherwise+ // restore an opener that remains in the underlying dialog.+ queueMicrotask(() => {+ const focusedDialog = document.activeElement instanceof HTMLElement+ ? document.activeElement.closest('[role="dialog"][data-state="open"]')+ : null;+ if (focusedDialog) return;+ if (previousFocus.isConnected) previousFocus.focus();+ });}}>{/* Bottom-sheet drag handle — mobile only. */}diff --git a/ui/src/components/ui/image-viewer.test.tsx b/ui/src/components/ui/image-viewer.test.tsxindex 5ae597f65..9057fa2a7 100644--- a/ui/src/components/ui/image-viewer.test.tsx+++ b/ui/src/components/ui/image-viewer.test.tsx@@ -122,6 +122,19 @@ describe('ImageViewerProvider — paging belongs to the gallery, not to every imexpect(document.querySelector('img[src="/api/media/med_2"]')).toBeNull();});+ it('restores focus to the image opener after closing', async () => {+ mount({ isolated: true });+ const opener = screen.getByText('open');+ opener.focus();+ fireEvent.click(opener);+ const dialog = screen.getByRole('dialog');+ expect(dialog.contains(document.activeElement)).toBe(true);++ fireEvent.click(screen.getByLabelText('Close'));+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());+ expect(document.activeElement).toBe(opener);+ });+it('closes on Escape either way', () => {mount({ isolated: true });fireEvent.click(screen.getByText('open'));@@ -225,6 +238,7 @@ describe('ImageViewerProvider — retained route activity owns global keys', ()expect(document.querySelector('img')).toBe(image);expect(document.querySelector('img')?.getAttribute('src')).toBe(GALLERY[0]);expect(document.querySelector('[role="dialog"]')).not.toBeNull();+ expect(document.querySelector('[role="dialog"]')?.getAttribute('aria-hidden')).toBe('true');} finally {window.removeEventListener('keydown', foreground);}diff --git a/ui/src/components/ui/image-viewer.tsx b/ui/src/components/ui/image-viewer.tsxindex 2dca26dcb..a6604b09c 100644--- a/ui/src/components/ui/image-viewer.tsx+++ b/ui/src/components/ui/image-viewer.tsx@@ -1,11 +1,14 @@import * as React from 'react';+import * as DialogPrimitive from '@radix-ui/react-dialog';import { useTranslation } from 'react-i18next';import { ChevronLeft, ChevronRight, Download, X, ZoomIn, ZoomOut } from 'lucide-react';import { TransformWrapper, TransformComponent, type ReactZoomPanPinchRef } from 'react-zoom-pan-pinch';import { Button } from '@/components/ui/button';+import { Dialog, DialogOverlay, DialogPortal, DialogTitle } from '@/components/ui/dialog';import { handleMediaDownloadClick, mediaDownloadHref } from '@/lib/downloadMedia';-import { useRouteSurfaceWindowEvent } from '@/lib/routeSurfaceActivity';+import { useRouteSurfaceActive, useRouteSurfaceWindowEvent } from '@/lib/routeSurfaceActivity';+import { cn } from '@/lib/utils';import { ImageViewerContext, type ImageViewerOpenOptions } from './image-viewer-context';// A session-scoped image lightbox. ChatPage computes the ordered list of media-@@ -56,9 +59,11 @@ export const ImageViewerProvider: React.FC<{ images: string[]; children: React.R[],);const close = React.useCallback(() => setView(null), []);+ const routeSurfaceActive = useRouteSurfaceActive();// Controls the zoom/pan transform (wired to the desktop +/- buttons). The// wrapper is keyed on ``src`` so paging to another image remounts it back to 1x.const transformRef = React.useRef<ReactZoomPanPinchRef>(null);+ const previousFocusRef = React.useRef<HTMLElement | null>(null);// True while/after a pan in the current press, so the trailing click (which may// land on the dark stage after dragging a zoomed image) doesn't close the modal.// Reset on each pointer-down; clicking the empty stage WITHOUT panning closes.@@ -116,37 +121,66 @@ export const ImageViewerProvider: React.FC<{ images: string[]; children: React.Rconst ctx = React.useMemo(() => ({ open }), [open]);return (- <ImageViewerContext.Provider value={ctx}>- {children}- {src && (- <div- className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6 backdrop-blur-sm"- onPointerDown={() => {- interactedRef.current = false;- }}- onClick={(e) => {- // A real pan happened this press → don't treat the release as a close.- if (interactedRef.current) return;- // Keep the viewer open only when the click is on the VISIBLE image:- // inside the image rect AND inside the stage. (A zoomed image's rect- // overflows the stage; those clipped parts are dark margin → close.)- const inside = (rect?: DOMRect) =>- !!rect &&- e.clientX >= rect.left &&- e.clientX <= rect.right &&- e.clientY >= rect.top &&- e.clientY <= rect.bottom;- if (- inside(imgRef.current?.getBoundingClientRect()) &&- inside(stageRef.current?.getBoundingClientRect())- ) {- return;- }- close();- }}- role="dialog"- aria-modal="true"- >+ <Dialog+ open={src !== null && routeSurfaceActive}+ onOpenChange={(next) => { if (!next) close(); }}+ >+ <ImageViewerContext.Provider value={ctx}>+ {children}+ {src && (+ <DialogPortal forceMount>+ {routeSurfaceActive && <DialogOverlay className="bg-black/80 backdrop-blur-sm" />}+ <DialogPrimitive.Content+ forceMount+ aria-describedby={undefined}+ aria-hidden={!routeSurfaceActive || undefined}+ inert={!routeSurfaceActive || undefined}+ className={cn(+ 'fixed inset-0 z-50 flex items-center justify-center p-6 focus:outline-none',+ !routeSurfaceActive && 'pointer-events-none invisible',+ )}+ onEscapeKeyDown={(event) => {+ if (!routeSurfaceActive) event.preventDefault();+ }}+ onOpenAutoFocus={() => {+ previousFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;+ }}+ onCloseAutoFocus={(event) => {+ if (!routeSurfaceActive) {+ event.preventDefault();+ return;+ }+ const previousFocus = previousFocusRef.current;+ if (previousFocus?.isConnected) {+ event.preventDefault();+ previousFocus.focus();+ }+ }}+ onPointerDown={() => {+ interactedRef.current = false;+ }}+ onClick={(e) => {+ // A real pan happened this press → don't treat the release as a close.+ if (interactedRef.current) return;+ // Keep the viewer open only when the click is on the VISIBLE image:+ // inside the image rect AND inside the stage. (A zoomed image's rect+ // overflows the stage; those clipped parts are dark margin → close.)+ const inside = (rect?: DOMRect) =>+ !!rect &&+ e.clientX >= rect.left &&+ e.clientX <= rect.right &&+ e.clientY >= rect.top &&+ e.clientY <= rect.bottom;+ if (+ inside(imgRef.current?.getBoundingClientRect()) &&+ inside(stageRef.current?.getBoundingClientRect())+ ) {+ return;+ }+ close();+ }}+ >+ <DialogTitle className="sr-only">{t('chat.media.preview')}</DialogTitle><div className="absolute right-4 top-4 z-10 flex items-center gap-2">{/* Zoom buttons: a pointer-device affordance (touch zooms by pinch).stopPropagation so clicking a control doesn't also close the viewer. */}@@ -272,8 +306,10 @@ export const ImageViewerProvider: React.FC<{ images: string[]; children: React.R{index + 1} / {gallery.length}</span>)}- </div>+ </DialogPrimitive.Content>+ </DialogPortal>)}- </ImageViewerContext.Provider>+ </ImageViewerContext.Provider>+ </Dialog>);};diff --git a/ui/src/components/workbench/CreateViaChatDialog.tsx b/ui/src/components/workbench/CreateViaChatDialog.tsxindex 928e55a5d..a54f7409d 100644--- a/ui/src/components/workbench/CreateViaChatDialog.tsx+++ b/ui/src/components/workbench/CreateViaChatDialog.tsx@@ -1,11 +1,12 @@import { useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';import { useNavigate } from 'react-router-dom';-import { ArrowRight, Loader2, Sparkles, X } from 'lucide-react';+import { ArrowRight, Loader2, Sparkles } from 'lucide-react';import { useApi } from '../../context/ApiContext';import type { WorkbenchProject } from '../../context/ApiContext';import { Button } from '../ui/button';+import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog';import { Select } from '../ui/select';import { errorMessage } from '@/lib/errorMessage';@@ -92,34 +93,19 @@ export const CreateViaChatDialog: React.FC<CreateViaChatDialogProps> = ({ kind,const noProjects = projects !== null && projects.length === 0;return (- <div- className="fixed inset-0 z-50 flex items-center justify-center overflow-y-auto bg-[#080812F0] px-4 py-4"- role="dialog"- aria-modal="true"- aria-label={t('harness.createDialog.title')}- onClick={onClose}- >- <div+ <Dialog open onOpenChange={(next) => { if (!next) onClose(); }}>+ <DialogContent+ closeLabel={t('harness.createDialog.cancel')}className="flex min-w-0 max-h-[calc(100dvh-2rem)] w-full max-w-[500px] flex-col items-center gap-5 overflow-y-auto rounded-2xl border border-violet/30 bg-surface p-7 shadow-[0_24px_48px_-6px_rgba(0,0,0,0.8),var(--shadow-glow-lg-violet)]"- onClick={(e) => e.stopPropagation()}>- <button- type="button"- aria-label={t('harness.createDialog.cancel')}- onClick={onClose}- className="absolute right-4 top-4 text-muted transition hover:text-foreground"- >- <X className="size-4" />- </button>-{/* Hero icon — 64x64 violet-soft tile with glow */}<div className="flex size-16 items-center justify-center rounded-2xl border border-violet/30 bg-violet-soft text-violet-ink shadow-glow-md-violet"><Sparkles className="size-[30px]" /></div><div className="flex min-w-0 flex-col gap-1.5 text-center">- <div className="text-[20px] font-bold text-foreground">{t('harness.createDialog.title')}</div>- <div className="text-[12px] italic text-muted">{t('harness.createDialog.subtitle')}</div>+ <DialogTitle className="text-[20px] font-bold text-foreground">{t('harness.createDialog.title')}</DialogTitle>+ <DialogDescription className="text-[12px] italic text-muted">{t('harness.createDialog.subtitle')}</DialogDescription></div><div className="flex w-full flex-col gap-2.5 rounded-xl border border-border bg-foreground/[0.015] px-[18px] py-4">@@ -193,7 +179,7 @@ export const CreateViaChatDialog: React.FC<CreateViaChatDialogProps> = ({ kind,)}</Button></div>- </div>- </div>+ </DialogContent>+ </Dialog>);};diff --git a/ui/src/components/workbench/FilePicker.tsx b/ui/src/components/workbench/FilePicker.tsxindex 162941b3a..f1d80d28b 100644--- a/ui/src/components/workbench/FilePicker.tsx+++ b/ui/src/components/workbench/FilePicker.tsx@@ -1,5 +1,6 @@import { useCallback, useEffect, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';+import * as DialogPrimitive from '@radix-ui/react-dialog';import { ChevronRight, File as FileIcon, Folder, FolderPlus, Loader2, X } from 'lucide-react';import clsx from 'clsx';@@ -17,6 +18,7 @@ import {type FsEntry,} from '../../lib/filesApi';import { Button } from '../ui/button';+import { Dialog, DialogTitle } from '../ui/dialog';export type FilePickerMode = 'open-directory' | 'save-file';@@ -61,6 +63,7 @@ export const FilePicker: React.FC<{const [showHidden, setShowHidden] = useState(false);const navSeq = useRef(0);+ const previousFocusRef = useRef<HTMLElement | null>(null);const navigate = useCallback((path: string) => {const seq = ++navSeq.current;@@ -167,19 +170,35 @@ export const FilePicker: React.FC<{const canConfirm = !!cwd && !submitting && (mode === 'open-directory' || name.trim() !== '');return (- // Scoped to the owning window (absolute, not a body portal) so it inherits the window's theme.- <div className="absolute inset-0 z-30 grid place-items-center bg-black/50 p-5" onClick={onCancel} role="presentation">- <div- className="flex h-[420px] w-[600px] max-w-full max-h-full flex-col overflow-hidden rounded-xl border border-border-strong bg-surface-2 shadow-[0_24px_64px_-12px_rgba(0,0,0,0.7)]"- onClick={(e) => e.stopPropagation()}- role="dialog"- aria-modal="true"- >- {/* Title + close */}- <div className="flex items-center gap-2 border-b border-border px-3.5 py-2.5">- <span className="flex-1 truncate text-[13px] font-semibold text-foreground">- {t(mode === 'open-directory' ? 'apps.picker.openFolderTitle' : 'apps.picker.saveFileTitle')}- </span>+ // Scoped to the owning window (not a body portal) so it inherits the window's theme.+ <Dialog open onOpenChange={(next) => { if (!next) onCancel(); }}>+ <div className="absolute inset-0 z-30 grid place-items-center bg-black/50 p-5" role="presentation">+ <DialogPrimitive.Content+ aria-describedby={undefined}+ className="relative z-10 flex h-[420px] w-[600px] max-w-full max-h-full flex-col overflow-hidden rounded-xl border border-border-strong bg-surface-2 shadow-[0_24px_64px_-12px_rgba(0,0,0,0.7)] focus:outline-none"+ onOpenAutoFocus={() => {+ previousFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;+ }}+ onCloseAutoFocus={(event) => {+ const previousFocus = previousFocusRef.current;+ if (previousFocus?.isConnected) {+ event.preventDefault();+ previousFocus.focus();+ }+ }}+ onEscapeKeyDown={(event) => {+ if (newFolder !== null) {+ event.preventDefault();+ setNewFolder(null);+ }+ }}+ onClick={(e) => e.stopPropagation()}+ >+ {/* Title + close */}+ <div className="flex items-center gap-2 border-b border-border px-3.5 py-2.5">+ <DialogTitle className="flex-1 truncate p-0 text-[13px] font-semibold text-foreground">+ {t(mode === 'open-directory' ? 'apps.picker.openFolderTitle' : 'apps.picker.saveFileTitle')}+ </DialogTitle><Button type="button" size="icon" variant="ghost" className="size-7 text-muted" aria-label={t('common.close')} onClick={onCancel}><X className="size-4" /></Button>@@ -245,7 +264,11 @@ export const FilePicker: React.FC<{onChange={(e) => setNewFolder(e.target.value)}onKeyDown={(e) => {if (e.key === 'Enter') void createFolder(newFolder);- else if (e.key === 'Escape') setNewFolder(null);+ else if (e.key === 'Escape') {+ e.preventDefault();+ e.stopPropagation();+ setNewFolder(null);+ }}}// Blur abandons the inline input — only Enter creates the folder, so cancelling the// picker (which blurs the input first) can't silently makeDir a folder.@@ -307,8 +330,9 @@ export const FilePicker: React.FC<{{t(mode === 'open-directory' ? 'apps.picker.selectFolder' : 'apps.picker.save')}</Button></div>+ </DialogPrimitive.Content></div>- </div>+ </Dialog>);};diff --git a/ui/src/components/workbench/NewAgentDialog.test.tsx b/ui/src/components/workbench/NewAgentDialog.test.tsxindex 0daccfc51..a91013350 100644--- a/ui/src/components/workbench/NewAgentDialog.test.tsx+++ b/ui/src/components/workbench/NewAgentDialog.test.tsx@@ -2,7 +2,9 @@import { afterEach, describe, expect, it, vi } from 'vitest';import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import userEvent from '@testing-library/user-event';import { MemoryRouter, useLocation } from 'react-router-dom';+import { useState } from 'react';import { InstanceAuthorizationContext } from '../../context/InstanceAuthorizationContext';import { RouteSurfaceActiveContext } from '../../lib/routeSurfaceActivity';@@ -104,6 +106,30 @@ afterEach(() => {});describe('NewAgentDialog', () => {+ it('uses Radix focus lifecycle for Escape and focus restoration', async () => {+ modelCatalog = { models: [] };+ apiRef.current = { createVibeAgent: vi.fn() };+ const Harness = () => {+ const [open, setOpen] = useState(false);+ return (+ <>+ <button type="button" onClick={() => setOpen(true)}>open-agent-dialog</button>+ <NewAgentDialog open={open} onClose={() => setOpen(false)} onCreated={vi.fn()} />+ </>+ );+ };++ render(<MemoryRouter><Harness /></MemoryRouter>);+ const trigger = screen.getByRole('button', { name: 'open-agent-dialog' });+ await userEvent.click(trigger);+ const dialog = await screen.findByRole('dialog');+ expect(dialog.contains(document.activeElement)).toBe(true);++ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());+ expect(document.activeElement).toBe(trigger);+ });+// The picker used a second label table, so its Claude label disagreed with// Settings and Model Hub. All backend choices share the catalog brands, and// they follow the shared display order, the built-in Vibey first.diff --git a/ui/src/components/workbench/NewAgentDialog.tsx b/ui/src/components/workbench/NewAgentDialog.tsxindex 7fb3d01d3..4246935eb 100644--- a/ui/src/components/workbench/NewAgentDialog.tsx+++ b/ui/src/components/workbench/NewAgentDialog.tsx@@ -1,6 +1,6 @@import { useEffect, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';-import { ArrowRight, Maximize2, X } from 'lucide-react';+import { ArrowRight, Maximize2 } from 'lucide-react';import clsx from 'clsx';import { useApi } from '../../context/ApiContext';@@ -14,9 +14,9 @@ import type { ComboboxOption } from '../ui/combobox';import { Input } from '../ui/input';import { Textarea } from '../ui/textarea';import { EditorDialog } from '../ui/editor-dialog';+import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog';import { Button } from '../ui/button';import { errorMessage } from '@/lib/errorMessage';-import { useRouteSurfaceWindowEvent } from '@/lib/routeSurfaceActivity';import { getBackendUiMeta, type AgentBackendId } from '@/lib/agentBackends';import { BackendAvatar } from '../visual';import { BACKEND_ORDER, BACKEND_LABEL } from '@/lib/backendAccent';@@ -29,7 +29,7 @@ const BACKEND_OPTIONS = BACKEND_ORDER.map((id) => ({}));interface NewAgentDialogProps {- /** When false the modal renders nothing — controlled by the parent. */+ /** When false the dialog stays closed — the parent owns its visibility. */open: boolean;onClose: () => void;/** Called after a successful POST /agents with the new agent. */@@ -141,14 +141,6 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o}}, [effortOptions, effort]);- useRouteSurfaceWindowEvent('keydown', (event) => {- // Don't let Esc close the whole create dialog when the expand editor is- // open on top — that Esc belongs to the editor.- if (event.key === 'Escape' && !editorOpen) onClose();- }, open);-- if (!open) return null;-const canSubmit = name.trim().length > 0 && !submitting && catalogAnswered;const handleSubmit = async () => {@@ -203,27 +195,19 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, oreturn (<>- <div- className="fixed inset-0 z-50 flex items-center justify-center overflow-y-auto bg-black/60 px-4 py-4"- role="dialog"- aria-modal="true"- onClick={onClose}- >- <div- className="flex min-w-0 max-h-[calc(100dvh-2rem)] w-full max-w-[520px] flex-col gap-5 overflow-y-auto rounded-2xl border border-border-strong bg-surface p-7 shadow-[0_24px_64px_-12px_rgba(0,0,0,0.6)]"- onClick={(e) => e.stopPropagation()}- >- <div className="flex min-w-0 items-start justify-between gap-3">- <div className="min-w-0 flex-1">- <h2 className="break-words text-[18px] font-bold text-foreground [overflow-wrap:anywhere]">{t('agents.create.title')}</h2>- <p className="mt-1 max-w-[420px] text-[11.5px] leading-relaxed text-muted">- {t('agents.create.body')}- </p>+ <Dialog open={open} onOpenChange={(next) => { if (!next) onClose(); }}>+ <DialogContent+ closeLabel={t('common.close')}+ className="flex min-w-0 max-h-[calc(100dvh-2rem)] w-full max-w-[520px] flex-col gap-5 overflow-y-auto rounded-2xl border border-border-strong bg-surface p-7 shadow-[0_24px_64px_-12px_rgba(0,0,0,0.6)]"+ >+ <div className="flex min-w-0 items-start justify-between gap-3">+ <div className="min-w-0 flex-1">+ <DialogTitle className="break-words text-[18px] font-bold text-foreground [overflow-wrap:anywhere]">{t('agents.create.title')}</DialogTitle>+ <DialogDescription className="mt-1 max-w-[420px] text-[11.5px] leading-relaxed text-muted">+ {t('agents.create.body')}+ </DialogDescription>+ </div></div>- <button onClick={onClose} className="text-muted hover:text-foreground" aria-label={t('common.close')}>- <X className="size-4" />- </button>- </div>{/* Backend picker */}<div className="flex flex-col gap-2">@@ -405,11 +389,10 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o<ArrowRight className="size-3.5" /></Button></div>- </div>- </div>- {/* Rendered outside the create-dialog wrapper so its portal clicks- (textarea, preview toggle, Save) don't bubble to the wrapper's- onClick=onClose and discard the in-progress form. */}+ </DialogContent>+ </Dialog>+ {/* The editor is a nested Radix dialog, so its portal interactions stay+ outside this form's focus scope and do not discard the draft. */}<EditorDialogopen={editorOpen}onClose={() => setEditorOpen(false)}diff --git a/ui/src/components/workbench/NewProjectDialog.tsx b/ui/src/components/workbench/NewProjectDialog.tsxindex dc2b73c1a..77a181277 100644--- a/ui/src/components/workbench/NewProjectDialog.tsx+++ b/ui/src/components/workbench/NewProjectDialog.tsx@@ -1,11 +1,12 @@import { useEffect, useLayoutEffect, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';-import { Folder, FolderOpen, Loader2, X } from 'lucide-react';+import { Folder, FolderOpen, Loader2 } from 'lucide-react';import type { WorkbenchProject } from '../../context/ApiContext';import { useWorkbenchProjectsActions } from '../../context/WorkbenchProjectsContext';import { FolderBrowser } from '../ui/folder-browser';import { Button } from '../ui/button';+import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog';import { Input } from '../ui/input';import { errorMessage } from '@/lib/errorMessage';import { useRouteSurfaceActive } from '@/lib/routeSurfaceActivity';@@ -95,35 +96,21 @@ export const NewProjectDialog: React.FC<NewProjectDialogProps> = ({ onClose, onCif (!surfaceActive || completion) return null;return (- <div- className="fixed inset-0 z-50 flex items-center justify-center overflow-y-auto bg-black/50 px-4 py-4"- role="dialog"- aria-modal="true"- aria-label={t('workbench.newProjectDialog.title')}- onClick={close}- >- <div+ <Dialog open onOpenChange={(next) => { if (!next) close(); }}>+ <DialogContent+ closeLabel={t('workbench.newProjectDialog.cancel')}className="flex min-w-0 max-h-[calc(100dvh-2rem)] w-full max-w-md flex-col gap-4 overflow-y-auto rounded-2xl border border-border-strong bg-surface p-5 shadow-[0_24px_64px_-12px_rgba(0,0,0,0.6)]"- onClick={(e) => e.stopPropagation()}><div className="flex min-w-0 items-start gap-3"><div className="flex size-9 items-center justify-center rounded-lg border border-mint/30 bg-mint/[0.08] text-mint-ink"><Folder className="size-4" /></div><div className="flex min-w-0 flex-1 flex-col gap-0.5">- <div className="text-[14px] font-bold text-foreground">{t('workbench.newProjectDialog.title')}</div>- <div className="text-[11.5px] leading-relaxed text-muted">+ <DialogTitle className="text-[14px] font-bold text-foreground">{t('workbench.newProjectDialog.title')}</DialogTitle>+ <DialogDescription className="text-[11.5px] leading-relaxed text-muted">{t('workbench.newProjectDialog.description')}- </div>+ </DialogDescription></div>- <button- type="button"- onClick={close}- aria-label={t('workbench.newProjectDialog.cancel')}- className="text-muted transition hover:text-foreground"- >- <X className="size-4" />- </button></div><div className="flex flex-col gap-1.5">@@ -190,7 +177,7 @@ export const NewProjectDialog: React.FC<NewProjectDialogProps> = ({ onClose, onC)}</Button></div>- </div>- </div>+ </DialogContent>+ </Dialog>);};diff --git a/ui/src/components/workbench/ProjectDefaultFolder.test.tsx b/ui/src/components/workbench/ProjectDefaultFolder.test.tsxindex 0dcf48279..d91e3c483 100644--- a/ui/src/components/workbench/ProjectDefaultFolder.test.tsx+++ b/ui/src/components/workbench/ProjectDefaultFolder.test.tsx@@ -1,7 +1,7 @@/* @vitest-environment jsdom */import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { cleanup, render, waitFor } from '@testing-library/react';+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';import { MemoryRouter } from 'react-router-dom';import type { WorkbenchProject } from '../../context/ApiContext';@@ -68,6 +68,38 @@ describe.each(['browser', 'picker'] as const)('%s default folder', (surface) =>});});+it('closes on Escape through the dialog lifecycle', async () => {+ const onCancel = vi.fn();+ render(<FilePicker mode="open-directory" onCancel={onCancel} onConfirm={() => {}} />);+ await waitFor(() => expect(state.listDir).toHaveBeenCalled());++ fireEvent.keyDown(screen.getByRole('dialog'), { key: 'Escape' });+ expect(onCancel).toHaveBeenCalledOnce();+});++it('uses the first Escape to abandon an inline folder name', async () => {+ const onCancel = vi.fn();+ render(<FilePicker mode="open-directory" onCancel={onCancel} onConfirm={() => {}} />);+ await waitFor(() => expect(state.listDir).toHaveBeenCalled());++ fireEvent.click(screen.getByRole('button', { name: 'apps.picker.newFolder' }));+ const input = screen.getByPlaceholderText('apps.picker.newFolderName');+ fireEvent.keyDown(input, { key: 'Escape' });++ expect(screen.queryByPlaceholderText('apps.picker.newFolderName')).toBeNull();+ expect(onCancel).not.toHaveBeenCalled();+});++it('dismisses through Radix when clicking outside the picker', async () => {+ const onCancel = vi.fn();+ render(<FilePicker mode="open-directory" onCancel={onCancel} onConfirm={() => {}} />);+ await waitFor(() => expect(state.listDir).toHaveBeenCalled());+ await new Promise((resolve) => setTimeout(resolve, 0));++ fireEvent.pointerDown(document.body);+ fireEvent.click(document.body);+ await waitFor(() => expect(onCancel).toHaveBeenCalledOnce());+});it('keeps an explicit picker path ahead of project defaults', async () => {render(<FilePicker mode="open-directory" initialPath="/tmp/explicit" onCancel={() => {}} onConfirm={() => {}} />);await waitFor(() => expect(state.listDir).toHaveBeenCalledWith('/tmp/explicit', false));diff --git a/ui/src/components/workbench/RunAgentDialog.tsx b/ui/src/components/workbench/RunAgentDialog.tsxindex d945f1c26..98666bf4a 100644--- a/ui/src/components/workbench/RunAgentDialog.tsx+++ b/ui/src/components/workbench/RunAgentDialog.tsx@@ -1,11 +1,12 @@import { useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';import { useNavigate } from 'react-router-dom';-import { ArrowRight, Loader2, Play, X } from 'lucide-react';+import { ArrowRight, Loader2, Play } from 'lucide-react';import { useApi } from '../../context/ApiContext';import type { VibeAgentFull, WorkbenchProject } from '../../context/ApiContext';import { Button } from '../ui/button';+import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog';import { Select } from '../ui/select';import { errorMessage } from '@/lib/errorMessage';@@ -76,35 +77,21 @@ export const RunAgentDialog: React.FC<RunAgentDialogProps> = ({ agent, onClose }const noProjects = projects !== null && projects.length === 0;return (- <div- className="fixed inset-0 z-50 flex items-center justify-center overflow-y-auto bg-black/60 px-4 py-4"- role="dialog"- aria-modal="true"- aria-label={t('agents.runDialog.title')}- onClick={onClose}- >- <div+ <Dialog open onOpenChange={(next) => { if (!next) onClose(); }}>+ <DialogContent+ closeLabel={t('common.close')}className="flex min-w-0 max-h-[calc(100dvh-2rem)] w-full max-w-md flex-col gap-4 overflow-y-auto rounded-2xl border border-border-strong bg-surface p-5 shadow-[0_24px_64px_-12px_rgba(0,0,0,0.6)]"- onClick={(e) => e.stopPropagation()}><div className="flex min-w-0 items-start gap-3"><div className="flex size-9 items-center justify-center rounded-lg border border-mint/30 bg-mint-soft text-mint-ink"><Play className="size-4" /></div><div className="flex min-w-0 flex-1 flex-col gap-0.5">- <div className="text-[14px] font-bold text-foreground">{t('agents.runDialog.title')}</div>- <div className="text-[11.5px] leading-relaxed text-muted">+ <DialogTitle className="text-[14px] font-bold text-foreground">{t('agents.runDialog.title')}</DialogTitle>+ <DialogDescription className="text-[11.5px] leading-relaxed text-muted">{t('agents.runDialog.description')}- </div>+ </DialogDescription></div>- <button- type="button"- onClick={onClose}- aria-label={t('common.close')}- className="text-muted transition hover:text-foreground"- >- <X className="size-4" />- </button></div><div className="flex flex-col gap-1.5">@@ -165,7 +152,7 @@ export const RunAgentDialog: React.FC<RunAgentDialogProps> = ({ agent, onClose })}</Button></div>- </div>- </div>+ </DialogContent>+ </Dialog>);};