Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

fix(ui): align settings dismissal modes (#2161)

Call Whitec6dfbbccbe06
diff --git a/docs/plans/2026-09-20-settings-general-polish.md b/docs/plans/2026-09-20-settings-general-polish.md
index ed401afb8..5b1ebdbdc 100644
--- a/docs/plans/2026-09-20-settings-general-polish.md
+++ b/docs/plans/2026-09-20-settings-general-polish.md
@@ -155,31 +155,26 @@ the publisher, feeds the rule directly.
`--app-sidebar-w` offset and a border, so the two edges stay together while the
sidebar is dragged. It publishes `data-settings-menu-placement` for tests.
- It also decides what an interaction *outside* the surface means, and inline
- turns out not to have an outside in the sense that handler assumes. Inline
- covers everything right of the sidebar, so what stays reachable is the sidebar
- column (z-10, left of the surface) and whatever the shell floats above the
- z-30 surface: the Apps launcher and its Dock at z-40, menus and floating
- details at z-50. Every one of those belongs to the live shell and already owns
- what it does — there is no neutral background left to click at. So **inline
- does not dismiss on outside interaction at all**, and is left by Escape, by the
- Settings toggle, or by navigating.
-
- That is deletion rather than exemption, and deliberately so. The resize edge
- moves this surface's own left edge, so grabbing it must not close what the drag
- is laying out; a sidebar link already navigates, and that navigation *is* the
- way out — letting dismissal fire too would race two navigations
- (`closeSettingsOverlay` traverses history asynchronously while the link pushes
- synchronously) and could land on the retained origin instead of the route that
- was clicked. Naming the exempt surfaces cannot express this, because
- `AppsLauncher` portals itself to `document.body` to clear the route panel's
- stacking context: it belongs to the sidebar without descending from it, and so
- do the menus and details beside it. Any DOM-ancestry test covers only the
- portals someone remembered.
-
- Standalone keeps the dismissal that shipped, including its single
- `data-settings-toggle` exemption — it does own the whole viewport, so "outside"
- there means what it always did.
+ It also decides what an interaction *outside* the surface means. Inline
+ dismisses when a non-owning shell control is clicked, while controls that own
+ their outside interaction declare `data-settings-interaction-owner` (or use
+ an anchor / the Settings toggle) so Radix does not perform a second exit. The
+ owner then performs the only navigation, handoff, or overlay action itself;
+ this keeps sidebar links, Dock tiles, and global feedback/toast controls from
+ racing `closeSettingsOverlay`'s history traversal.
+ A real outside dismissal records the control that caused it and returns focus
+ there instead of stealing focus back to the Settings opener.
+
+ This is an ownership boundary rather than DOM ancestry. `AppsLauncher` portals
+ its Dock to `document.body` to clear the route panel's stacking context, so
+ the Dock publishes the ownership marker at its own root and all of its window
+ controls inherit it. Standalone Settings keeps the whole viewport live and
+ never dismisses from outside interaction; its Settings toggle remains an
+ explicit close path. When a non-owning outside action opens a modal, the
+ foreground modal keeps focus ahead of the dismissed panel's return target.
+ Project and session context-menu rows declare ownership before pointer-down,
+ as do their menu triggers, so opening a portal never depends on its content
+ already being mounted.
- **`SettingsLayout`**'s rail is `var(--app-sidebar-w)` when standalone (so it
tracks even a dragged sidebar) and stays 196px inline, where spending a second
full-width column on a secondary nav would cost 496px of left chrome.
@@ -256,12 +251,14 @@ edited into `design.pen`.
- `SettingsLayout.test.tsx` — rail width per placement, including standalone where
the shell draws no sidebar while `inline` is stored.
- `SettingsOverlayRouteSurface.test.tsx` — the surface's left edge and border per
- placement, standalone where the shell draws no sidebar, and what an outside
- interaction means: inline dismisses on none of them — the resize edge, the
- sidebar's quiet space, a control *portaled* out of the sidebar, or the rest of
- the shell — while Escape and a sidebar link each still leave, in exactly one
- navigation. Standalone still dismisses on the same portaled control, which is
- the shipped behaviour. The portal case is the one an ancestry test cannot pass.
+ placement, standalone where the shell draws no sidebar, inline dismissal of
+ non-owning outside controls with focus retention, and exactly-one navigation
+ for sidebar links and a portaled window owner. Feedback ownership, modal
+ focus precedence, and standalone remaining open for outside controls are
+ covered too; the portal case is the one an ancestry test cannot pass.
+- `e2e/workbench-general/settings-dismissal.spec.ts` — a real project-row
+ right-click keeps inline Settings open while its menu opens. Escape dismisses
+ that menu first, then Settings on a separate press.
- `e2e/workbench-general/geometry.spec.ts` — measured in a browser: the 248 rail,
the card's background matching a neighbouring page's card, and inline actually
putting a live sidebar beside Settings at the sidebar's own width. It also
diff --git a/ui/e2e/workbench-general/settings-dismissal.spec.ts b/ui/e2e/workbench-general/settings-dismissal.spec.ts
new file mode 100644
index 000000000..3590e29b2
--- /dev/null
+++ b/ui/e2e/workbench-general/settings-dismissal.spec.ts
@@ -0,0 +1,27 @@
+import { expect, test } from '@playwright/test';
+import { DESKTOP, open, serveProduct } from './support';
+
+test('inline Settings stays open when the project row opens its context menu', async ({ page }) => {
+ const denied = await serveProduct(page);
+ await page.addInitScript(() => {
+ window.localStorage.setItem('avibe.settings.menu-placement.v1', 'inline');
+ });
+ await page.setViewportSize(DESKTOP);
+ await open(page, '/');
+ await page.locator('aside [data-settings-toggle="true"]').click();
+ const settings = page.locator('[data-settings-overlay="true"]');
+ await expect(settings).toHaveAttribute('data-settings-menu-placement', 'inline');
+
+ // The row receives pointerdown before contextmenu opens the portalled menu.
+ // Ownership must exist on this path before the menu content is mounted.
+ await page.locator('aside .project-drag-header').click({ button: 'right' });
+ await expect(page.getByRole('button', { name: 'Rename', exact: true })).toBeVisible();
+ await expect(settings).toBeVisible();
+ await expect(page).toHaveURL(/\/settings\/general$/);
+ await page.keyboard.press('Escape');
+ await expect(page.getByRole('button', { name: 'Rename', exact: true })).toHaveCount(0);
+ await expect(settings).toBeVisible();
+ await page.keyboard.press('Escape');
+ await expect(settings).toHaveCount(0);
+ expect(denied).toEqual([]);
+});
diff --git a/ui/src/components/AgentationToggle.tsx b/ui/src/components/AgentationToggle.tsx
index 42c312cac..3790e1ef8 100644
--- a/ui/src/components/AgentationToggle.tsx
+++ b/ui/src/components/AgentationToggle.tsx
@@ -61,12 +61,14 @@ export const AgentationToggle = () => {
if (!enabled) return null;
return (
- <Suspense fallback={null}>
- <Agentation
- copyToClipboard={false}
- onCopy={copyText}
- onSubmit={(output) => copyText(output)}
- />
- </Suspense>
+ <div data-settings-interaction-owner="true">
+ <Suspense fallback={null}>
+ <Agentation
+ copyToClipboard={false}
+ onCopy={copyText}
+ onSubmit={(output) => copyText(output)}
+ />
+ </Suspense>
+ </div>
);
};
diff --git a/ui/src/components/apps/Dock.tsx b/ui/src/components/apps/Dock.tsx
index 38be56200..357fc6f82 100644
--- a/ui/src/components/apps/Dock.tsx
+++ b/ui/src/components/apps/Dock.tsx
@@ -180,7 +180,7 @@ export const Dock: React.FC = () => {
};
return (
- <div className="relative">
+ <div className="relative" data-settings-interaction-owner="true">
{/* Bound the panel to the viewport and scroll horizontally: with many pinned
apps the resident row would otherwise run off-screen (the popover sits at
the bottom-left), leaving later tiles unreachable for open/reorder/unpin. */}
diff --git a/ui/src/components/settings/SettingsOverlayRouteSurface.test.tsx b/ui/src/components/settings/SettingsOverlayRouteSurface.test.tsx
index 230aa0903..bcd9833c9 100644
--- a/ui/src/components/settings/SettingsOverlayRouteSurface.test.tsx
+++ b/ui/src/components/settings/SettingsOverlayRouteSurface.test.tsx
@@ -191,6 +191,62 @@ const PortaledShellControl = () => createPortal(
document.body,
);
+const PortaledWindowOwner = ({ handoffRef }: { handoffRef: { current: boolean } }) => {
+ const location = useLocation();
+ const navigate = useNavigate();
+ const origin = useSettingsOverlayOrigin(location);
+ return createPortal(
+ <button
+ type="button"
+ data-settings-interaction-owner="true"
+ onClick={() => {
+ if (!origin) return;
+ handoffRef.current = true;
+ closeSettingsOverlay(navigate, origin);
+ }}
+ >
+ dock-window-tile
+ </button>,
+ document.body,
+ );
+};
+
+const PortaledModalProbe = () => {
+ const [open, setOpen] = useState(false);
+ return createPortal(
+ <>
+ <button type="button" onClick={() => setOpen(true)}>open-shell-modal</button>
+ {open ? (
+ <div role="dialog" aria-modal="true">
+ <input aria-label="shell modal input" autoFocus />
+ </div>
+ ) : null}
+ </>,
+ document.body,
+ );
+};
+
+const AgentationEscapeProbe = () => {
+ const [active, setActive] = useState(true);
+ return createPortal(
+ <div data-agentation-root="" data-settings-interaction-owner="true">
+ <div data-agentation-toolbar>
+ <div tabIndex={active ? -1 : 0}>
+ <button
+ type="button"
+ onKeyDown={(event) => {
+ if (event.key === 'Escape') setActive(false);
+ }}
+ >
+ feedback-toolbar
+ </button>
+ </div>
+ </div>
+ </div>,
+ document.body,
+ );
+};
+
const SettingsFrame = () => {
const location = useLocation();
const navigate = useNavigate();
@@ -286,6 +342,8 @@ const Harness = ({ desktop }: { desktop: boolean }) => {
themselves to `document.body` to clear the route panel's stacking
context, so they belong to the sidebar without descending from it. */}
<PortaledShellControl />
+ <PortaledWindowOwner handoffRef={handoffRef} />
+ <PortaledModalProbe />
<button type="button">shell-elsewhere</button>
<SettingsOverlayRouteSurface fallbackElement={<Navigate to="/" replace />}>
<Route path="/setup" element={<SetupProbe />} />
@@ -702,69 +760,79 @@ describe('SettingsOverlayRouteSurface', () => {
expect(surface.classList.contains('md:border-l')).toBe(dividedFromSidebar);
});
- it('never dismisses inline on an outside interaction, and still lets the user leave', async () => {
+ it.each(['shell-resizer', 'sidebar-idle', 'sidebar-portaled', 'shell-elsewhere'] as const)(
+ 'dismisses inline when %s is clicked',
+ async (outsideControl) => {
+ const user = userEvent.setup();
+ window.localStorage.setItem(SETTINGS_MENU_PLACEMENT_STORAGE_KEY, 'inline');
+ render(
+ <MemoryRouter initialEntries={['/chat/ses_1']}>
+ <RoutedHarness />
+ </MemoryRouter>,
+ );
+
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ expect(screen.getByRole('dialog', { name: 'nav.settings' })).toBeTruthy();
+ await user.click(screen.getByRole('button', { name: outsideControl }));
+ await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
+ expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_1');
+ },
+ );
+
+ it('keeps inline navigation on the clicked sidebar destination', async () => {
const user = userEvent.setup();
window.localStorage.setItem(SETTINGS_MENU_PLACEMENT_STORAGE_KEY, 'inline');
+ window.history.replaceState({ idx: 0 }, '');
render(
<MemoryRouter initialEntries={['/chat/ses_1']}>
<RoutedHarness />
</MemoryRouter>,
);
- const open = async () => {
- await user.click(screen.getByRole('link', { name: 'shell-settings' }));
- expect(screen.getByRole('dialog', { name: 'nav.settings' })).toBeTruthy();
- // Inline's whole premise is that the shell behind stays reachable, so
- // this dialog must never go modal: Radix's modal path inerts the page
- // behind it. Whether a layer *covers* the sidebar is a hit test, which
- // only a browser can run — `geometry.spec.ts` settles that half.
- expect(document.body.style.pointerEvents).not.toBe('none');
- };
- const stillOpen = () => expect(
- document.querySelector('[data-settings-overlay="true"]'),
- ).toBeTruthy();
-
- await open();
-
- // Grabbing the divider moves this surface's OWN left edge. Dismissing on it
- // would close the thing the drag is laying out.
- await user.click(screen.getByRole('button', { name: 'shell-resizer' }));
- stillOpen();
-
- // Nor is the sidebar's own quiet space a dismissal: inline puts these two
- // surfaces side by side, so the sidebar is a neighbour, not "outside".
- await user.click(screen.getByRole('button', { name: 'sidebar-idle' }));
- stillOpen();
-
- // The launcher and Dock belong to that column but portal above this layer,
- // so they are not descendants of it. Anything deciding this by DOM ancestry
- // passes the two cases above and fails here — which is the whole point of
- // not deciding it that way.
- await user.click(screen.getByRole('button', { name: 'sidebar-portaled' }));
- stillOpen();
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ // Model the browser history index that production's createBrowserRouter
+ // records when Settings is pushed above the retained origin. If outside
+ // dismissal also runs, closeSettingsOverlay would race this Link's push.
+ window.history.replaceState({ idx: 1 }, '');
+ await user.click(screen.getByRole('link', { name: 'sidebar-chat-link' }));
+ await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
+ expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_2');
+ });
- // Not even the rest of the shell: inline covers everything right of the
- // sidebar, so there is no neutral background left to click at.
- await user.click(screen.getByRole('button', { name: 'shell-elsewhere' }));
- stillOpen();
+ it('keeps focus on the inline control that dismisses Settings', async () => {
+ const user = userEvent.setup();
+ window.localStorage.setItem(SETTINGS_MENU_PLACEMENT_STORAGE_KEY, 'inline');
+ render(
+ <MemoryRouter initialEntries={['/chat/ses_1']}>
+ <RoutedHarness />
+ </MemoryRouter>,
+ );
- // Leaving is never in doubt, though. Escape still closes to the retained
- // origin...
- await user.keyboard('{Escape}');
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ const resizer = screen.getByRole('button', { name: 'shell-resizer' });
+ await user.click(resizer);
await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
- expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_1');
+ await waitFor(() => expect(document.activeElement).toBe(resizer));
+ });
- // ...and a sidebar link takes the user out by its own navigation, which is
- // exactly ONE navigation. Were dismissal to fire too, `closeSettingsOverlay`
- // would traverse history asynchronously and race this synchronous push back
- // to the retained origin.
- await open();
- await user.click(screen.getByRole('link', { name: 'sidebar-chat-link' }));
+ it('lets a portaled window owner close inline Settings exactly once', async () => {
+ const user = userEvent.setup();
+ window.localStorage.setItem(SETTINGS_MENU_PLACEMENT_STORAGE_KEY, 'inline');
+ window.history.replaceState({ idx: 0 }, '');
+ render(
+ <MemoryRouter initialEntries={['/chat/ses_1']}>
+ <RoutedHarness />
+ </MemoryRouter>,
+ );
+
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ window.history.replaceState({ idx: 1 }, '');
+ await user.click(screen.getByRole('button', { name: 'dock-window-tile' }));
await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
- expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_2');
+ expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_1');
});
- it('keeps the shipped outside dismissal for the standalone surface', async () => {
+ it('keeps standalone Settings open when an outside control is clicked', async () => {
const user = userEvent.setup();
render(
<MemoryRouter initialEntries={['/chat/ses_1']}>
@@ -772,13 +840,82 @@ describe('SettingsOverlayRouteSurface', () => {
</MemoryRouter>,
);
- // Standalone really does own the viewport — anything that floats above it is
- // outside in the ordinary sense, and closes it back to the retained origin.
await user.click(screen.getByRole('link', { name: 'shell-settings' }));
expect(screen.getByRole('dialog', { name: 'nav.settings' })).toBeTruthy();
await user.click(screen.getByRole('button', { name: 'sidebar-portaled' }));
- await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
+ expect(document.querySelector('[data-settings-overlay="true"]')).toBeTruthy();
+ });
+
+ it('lets an active feedback interaction consume Escape before Settings closes', async () => {
+ const user = userEvent.setup();
+ render(
+ <MemoryRouter initialEntries={['/chat/ses_1']}>
+ <RoutedHarness />
+ <AgentationEscapeProbe />
+ </MemoryRouter>,
+ );
+
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ await user.click(screen.getByRole('button', { name: 'feedback-toolbar' }));
+ await user.keyboard('{Escape}');
+
+ expect(document.querySelector('[data-settings-overlay="true"]')).toBeTruthy();
expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_1');
+
+ await user.keyboard('{Escape}');
+ await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
+ });
+
+ it('keeps inline Settings open while feedback owns the outside interaction', async () => {
+ const user = userEvent.setup();
+ window.localStorage.setItem(SETTINGS_MENU_PLACEMENT_STORAGE_KEY, 'inline');
+ render(
+ <MemoryRouter initialEntries={['/chat/ses_1']}>
+ <RoutedHarness />
+ <AgentationEscapeProbe />
+ </MemoryRouter>,
+ );
+
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ await user.click(screen.getByRole('button', { name: 'feedback-toolbar' }));
+ expect(document.querySelector('[data-settings-overlay="true"]')).toBeTruthy();
+ });
+
+ it('does not reuse an owner interaction as Escape return focus', async () => {
+ const user = userEvent.setup();
+ window.localStorage.setItem(SETTINGS_MENU_PLACEMENT_STORAGE_KEY, 'inline');
+ render(
+ <MemoryRouter initialEntries={['/chat/ses_1']}>
+ <RoutedHarness />
+ <AgentationEscapeProbe />
+ </MemoryRouter>,
+ );
+
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ await user.click(screen.getByRole('button', { name: 'feedback-toolbar' }));
+ await user.keyboard('{Escape}');
+ expect(document.querySelector('[data-settings-overlay="true"]')).toBeTruthy();
+ await user.keyboard('{Escape}');
+ await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
+ await waitFor(() => expect(document.activeElement).toBe(
+ screen.getByRole('link', { name: 'shell-settings' }),
+ ));
+ });
+
+ it('does not steal focus from a modal opened by an inline outside action', async () => {
+ const user = userEvent.setup();
+ window.localStorage.setItem(SETTINGS_MENU_PLACEMENT_STORAGE_KEY, 'inline');
+ render(
+ <MemoryRouter initialEntries={['/chat/ses_1']}>
+ <RoutedHarness />
+ </MemoryRouter>,
+ );
+
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ await user.click(screen.getByRole('button', { name: 'open-shell-modal' }));
+ const input = await screen.findByRole('textbox', { name: 'shell modal input' });
+ await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
+ await waitFor(() => expect(document.activeElement).toBe(input));
});
// Some shells draw no app sidebar at all — the setup wizard, a single-app tab.
diff --git a/ui/src/components/settings/SettingsOverlayRouteSurface.tsx b/ui/src/components/settings/SettingsOverlayRouteSurface.tsx
index dc9c93cde..bd9d30bec 100644
--- a/ui/src/components/settings/SettingsOverlayRouteSurface.tsx
+++ b/ui/src/components/settings/SettingsOverlayRouteSurface.tsx
@@ -41,6 +41,32 @@ const isForegroundFocusOwner = (element: Element | null): element is HTMLElement
return false;
};
+const isAgentationActive = (): boolean => (
+ // Agentation does not expose its active state through a callback. Its toolbar
+ // keeps the collapsed trigger at tabIndex=0 and switches its root container
+ // to tabIndex=-1 while feedback mode (and its annotation popup) is active.
+ document.querySelector(
+ '[data-agentation-root] [data-agentation-toolbar] > div[tabindex="-1"]',
+ ) !== null
+);
+
+const getOutsideFocusTarget = (target: EventTarget | null): HTMLElement | null => {
+ if (!(target instanceof Element)) return null;
+ const candidate = target.closest<HTMLElement>(
+ 'a[href], button:not([disabled]), input:not([disabled]), '
+ + 'select:not([disabled]), textarea:not([disabled]), '
+ + '[tabindex]:not([tabindex="-1"])',
+ );
+ return candidate instanceof HTMLElement && candidate.isConnected ? candidate : null;
+};
+
+const isInteractionOwner = (target: EventTarget | null): boolean => (
+ target instanceof Element
+ && target.closest(
+ 'a[href], [data-settings-toggle="true"], [data-settings-interaction-owner="true"]',
+ ) !== null
+);
+
export const SettingsOverlayRouteSurface = ({
children,
fallbackElement,
@@ -57,6 +83,7 @@ export const SettingsOverlayRouteSurface = ({
const locationRef = useRef(location);
const settingsVisitRef = useRef(0);
const focusFrameRef = useRef<number | null>(null);
+ const outsideFocusRef = useRef<HTMLElement | null>(null);
const focusHandoffRef = useSettingsFocusHandoff();
useLayoutEffect(() => {
settingsSurfaceOpenRef.current = settingsSurfaceOpen;
@@ -160,42 +187,42 @@ export const SettingsOverlayRouteSurface = ({
: 'left-0 border-l-0 md:border-l'}
aria-describedby={undefined}
onInteractOutside={(event) => {
- // Inline has no outside in the sense this handler assumes. It is
- // a pane beside a live shell, not a popup over an inert one, and
- // everything still reachable belongs to that shell: the sidebar
- // column left of this surface, plus the launcher, Dock, menus and
- // floating details it portals to `document.body` above this
- // layer. Each of those already owns what it does. The resize edge
- // moves this surface's own left edge, so grabbing it must not
- // close what the drag is laying out; a sidebar link navigates,
- // and that navigation IS the way out — were dismissal to fire
- // too, `closeSettingsOverlay`'s asynchronous history traversal
- // would race the link's synchronous push and could land on the
- // retained origin instead of the route that was clicked.
- //
- // Naming those surfaces is what a portal defeats: they are not
- // DOM descendants of the column they belong to, so any ancestry
- // test can only cover the ones someone remembered. Inline is left
- // by Escape, by the Settings toggle, or by navigating — never by
- // clicking its neighbour — so it simply does not dismiss.
- if (!standaloneMenu) {
- event.preventDefault();
- return;
- }
- // Standalone does own the whole viewport, and keeps the dismissal
- // that shipped with it. Only the toggle is exempt there, because
- // it closes this surface itself and must not do it twice.
const target = event.target;
- if (target instanceof Element && target.closest('[data-settings-toggle="true"]')) {
+ const isToggle = target instanceof Element
+ && target.closest('[data-settings-toggle="true"]') !== null;
+ const interactionOwner = isInteractionOwner(target);
+ // Keep focus on the control that caused an inline dismissal.
+ // The toggle is the same handoff for standalone's explicit
+ // close; other standalone interactions do not close Settings
+ // and must not leave a stale target for a later close.
+ if (isToggle || (!standaloneMenu && !interactionOwner)) {
+ outsideFocusRef.current = getOutsideFocusTarget(target);
+ } else {
+ outsideFocusRef.current = null;
+ }
+ // Controls that own their outside interaction must decide what
+ // happens next: a sidebar Link pushes its destination, the
+ // Settings toggle closes explicitly, Dock/window controls hand
+ // focus to a window, and global overlays remain usable. Prevent
+ // Radix's generic dismissal from racing those owners.
+ if (standaloneMenu || interactionOwner) {
event.preventDefault();
}
}}
+ onEscapeKeyDown={(event) => {
+ // Radix listens in the document capture phase, while Agentation
+ // clears its current annotation in a later document listener.
+ // Give an active annotation interaction first claim on Escape;
+ // the next Escape, after Agentation is inactive, closes Settings.
+ if (isAgentationActive()) event.preventDefault();
+ }}
onOpenAutoFocus={() => {
if (focusFrameRef.current !== null) {
window.cancelAnimationFrame(focusFrameRef.current);
focusFrameRef.current = null;
}
settingsVisitRef.current += 1;
+ outsideFocusRef.current = null;
// Freeze the origin focus for this visit. Retained app windows
// may focus themselves on return, before Radix's deferred close
// callback runs; that must not replace the initiating control.
@@ -214,7 +241,8 @@ export const SettingsOverlayRouteSurface = ({
}
const visit = settingsVisitRef.current;
const expectedOrigin = origin;
- const target = returnFocusRef.current;
+ const outsideTarget = outsideFocusRef.current;
+ const returnTarget = returnFocusRef.current;
focusFrameRef.current = window.requestAnimationFrame(() => {
focusFrameRef.current = null;
// A close callback may outlive a rapid Settings reopen or a
@@ -226,11 +254,15 @@ export const SettingsOverlayRouteSurface = ({
|| expectedOrigin === null
|| locationPath(locationRef.current) !== locationPath(expectedOrigin.location)
) return;
- if (target?.isConnected && !target.closest('[inert]')) {
- target.focus({ preventScroll: true });
+ if (isForegroundFocusOwner(document.activeElement)) return;
+ if (outsideTarget?.isConnected && !outsideTarget.closest('[inert]')) {
+ outsideTarget.focus({ preventScroll: true });
+ return;
+ }
+ if (returnTarget?.isConnected && !returnTarget.closest('[inert]')) {
+ returnTarget.focus({ preventScroll: true });
return;
}
- if (isForegroundFocusOwner(document.activeElement)) return;
const fallback = Array.from(
document.querySelectorAll<HTMLElement>('[data-settings-toggle="true"]'),
).find((candidate) => !candidate.closest('[inert]'));
diff --git a/ui/src/components/workbench/WorkbenchSidebar.tsx b/ui/src/components/workbench/WorkbenchSidebar.tsx
index 71ad43ab2..5a8001ed9 100644
--- a/ui/src/components/workbench/WorkbenchSidebar.tsx
+++ b/ui/src/components/workbench/WorkbenchSidebar.tsx
@@ -181,6 +181,7 @@ const InboxHoverPopover: React.FC<{
side="right"
align="start"
sideOffset={12}
+ data-settings-interaction-owner="true"
onOpenAutoFocus={(e) => e.preventDefault()}
role="dialog"
aria-label={t('workbench.inbox.title')}
@@ -406,6 +407,7 @@ export const SessionRow: React.FC<{
<Popover open={canManageMetadata && menuOpen} onOpenChange={(open) => canManageMetadata && setMenuOpen(open)}>
<PopoverAnchor asChild>
<div
+ data-settings-interaction-owner="true"
onContextMenu={(e) => {
if (!canManageMetadata) return;
e.preventDefault();
@@ -424,6 +426,7 @@ export const SessionRow: React.FC<{
>
<button
type="button"
+ data-settings-interaction-owner="true"
onClick={() => navigate(`/chat/${encodeURIComponent(session.id)}`)}
className="flex min-w-0 flex-1 items-center gap-2 text-left focus-visible:outline-none"
>
@@ -559,6 +562,7 @@ const ProjectRow: React.FC<{
return (
<div className="flex flex-col gap-0.5">
<div
+ data-settings-interaction-owner="true"
className="group flex items-center gap-1.5 rounded-md py-1.5 pl-1 pr-2 transition hover:bg-foreground/[0.04]"
title={project.folder_path}
onContextMenu={(e) => {
@@ -615,6 +619,7 @@ const ProjectRow: React.FC<{
<PopoverTrigger asChild>
<button
type="button"
+ data-settings-interaction-owner="true"
aria-label={t('workbench.projectActions')}
className={clsx(
'flex size-5 shrink-0 items-center justify-center rounded-md text-muted transition',
@@ -625,7 +630,11 @@ const ProjectRow: React.FC<{
<Ellipsis className="size-3" />
</button>
</PopoverTrigger>
- <PopoverContent align="end" className="w-[160px] p-1">
+ <PopoverContent
+ align="end"
+ data-settings-interaction-owner="true"
+ className="w-[160px] p-1"
+ >
<button
type="button"
onClick={() => {
@@ -697,6 +706,7 @@ const ProjectRow: React.FC<{
</Popover>}
{canChat && <button
type="button"
+ data-settings-interaction-owner="true"
aria-label={t('workbench.addSession')}
onClick={onCreateSession}
disabled={creatingSession}
diff --git a/ui/src/components/workbench/sessionActions.tsx b/ui/src/components/workbench/sessionActions.tsx
index 03e8c6fa8..bb92c7140 100644
--- a/ui/src/components/workbench/sessionActions.tsx
+++ b/ui/src/components/workbench/sessionActions.tsx
@@ -57,6 +57,7 @@ export const SessionActionsTrigger = React.forwardRef<HTMLButtonElement, Session
<Button
ref={ref}
type="button"
+ data-settings-interaction-owner="true"
variant="ghost"
size="icon"
aria-label={label}
@@ -226,6 +227,7 @@ export const SessionActionMenuContent: React.FC<{
return (
<PopoverContent
align={align}
+ data-settings-interaction-owner="true"
className={clsx('w-[176px] p-1', className)}
onCloseAutoFocus={(event) => {
if (!transferredFocus.current) return;
diff --git a/ui/src/context/ToastProvider.tsx b/ui/src/context/ToastProvider.tsx
index d44b62ccb..cdd14bfbc 100644
--- a/ui/src/context/ToastProvider.tsx
+++ b/ui/src/context/ToastProvider.tsx
@@ -125,7 +125,10 @@ export const ToastProvider: React.FC<{ children: React.ReactNode }> = ({ childre
Above z-50 on purpose: Radix portals its dialog overlay/content to
document.body at z-50, and a later sibling of #root wins a z-index tie,
so a toast raised from inside a modal painted behind the overlay. */}
- <div className="fixed bottom-[calc(5.5rem+env(safe-area-inset-bottom))] right-4 z-[100] flex flex-col gap-2 md:bottom-4">
+ <div
+ data-settings-interaction-owner="true"
+ className="fixed bottom-[calc(5.5rem+env(safe-area-inset-bottom))] right-4 z-[100] flex flex-col gap-2 md:bottom-4"
+ >
{toasts.map((toast) => (
<div
key={toast.id}