Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: move focus into Shell launcher and Run-on-App popovers, close on Escape, expose aria-haspopup (#9122)
[._.]/ Adam Eivyb404eabb1619
diff --git a/client/src/components/cos/tabs/schedule/RunTaskButton.jsx b/client/src/components/cos/tabs/schedule/RunTaskButton.jsxindex e715101ef9..39d5011616 100644--- a/client/src/components/cos/tabs/schedule/RunTaskButton.jsx+++ b/client/src/components/cos/tabs/schedule/RunTaskButton.jsx@@ -3,6 +3,8 @@ import { createPortal } from 'react-dom';import { CheckCircle2, ChevronDown, Loader2, Package, Play } from 'lucide-react';import { triggerButtonClass } from './scheduleConstants';import useClickOutside from '../../../../hooks/useClickOutside.js';+import useEscapeKey from '../../../../hooks/useEscapeKey.js';+import useFocusTrap from '../../../../hooks/useFocusTrap.js';import usePopoverPosition, { VIEWPORT_PADDING } from '../../../../hooks/usePopoverPosition.js';const MENU_WIDTH = 256; // w-64@@ -44,6 +46,14 @@ export default function RunTaskButton({ taskType, apps, onTrigger, installWide =// trigger-only containment check would read clicks on the panel as outside.useClickOutside([ref, popoverRef], open, () => setOpen(false));+ // Focus the trigger explicitly too: Safari does not focus a button on click,+ // so the trap's captured opener can be <body>.+ useEscapeKey(open, () => { setOpen(false); triggerRef.current?.focus(); });+ // Portaled to <body> and hidden until measured (menuStyle), so wait for that:+ // move focus into the panel, wrap Tab inside it, and+ // return focus to the trigger on close.+ useFocusTrap(open && !disabled && !!menuStyle, popoverRef);+// Without this, an open dropdown survives a flip to disabled and pops back open when re-enabled.useEffect(() => {if (disabled) setOpen(false);@@ -144,6 +154,7 @@ export default function RunTaskButton({ taskType, apps, onTrigger, installWide =disabled={disabled}aria-disabled={disabled || undefined}aria-busy={triggering || undefined}+ aria-haspopup="true"aria-expanded={open}className={triggerButtonClass(disabled)}>diff --git a/client/src/components/cos/tabs/schedule/RunTaskButton.test.jsx b/client/src/components/cos/tabs/schedule/RunTaskButton.test.jsxindex ec3b2a1f06..5086830fbf 100644--- a/client/src/components/cos/tabs/schedule/RunTaskButton.test.jsx+++ b/client/src/components/cos/tabs/schedule/RunTaskButton.test.jsx@@ -109,4 +109,19 @@ describe('RunTaskButton', () => {// narrowed by max-w, so it ran past the right edge instead of moving.expect(left + width).toBeLessThanOrEqual(window.innerWidth - 8);});++ it("moves focus into the app panel and Escape closes it, returning focus to the trigger", async () => {+ const user = userEvent.setup();+ render(<RunTaskButton taskType="review" apps={APPS} onTrigger={vi.fn()} />);+ const trigger = screen.getByRole("button", { name: /Run on App/i });+ expect(trigger.getAttribute("aria-haspopup")).toBe("true");+ await user.click(trigger);+ expect(trigger.getAttribute("aria-expanded")).toBe("true");+ expect(document.activeElement).toBe(screen.getByText("Example App").closest("button"));++ await user.keyboard("{Escape}");+ expect(screen.queryByText("Example App")).toBeNull();+ expect(trigger.getAttribute("aria-expanded")).toBe("false");+ expect(document.activeElement).toBe(trigger);+ });});diff --git a/client/src/components/shell/ShellProviderLauncher.jsx b/client/src/components/shell/ShellProviderLauncher.jsxindex 1c4f389bb6..0a458b1322 100644--- a/client/src/components/shell/ShellProviderLauncher.jsx+++ b/client/src/components/shell/ShellProviderLauncher.jsx@@ -4,6 +4,7 @@ import { Bot, ChevronDown, Search, Terminal, AlertTriangle } from 'lucide-react'import usePopoverPosition, { VIEWPORT_PADDING } from '../../hooks/usePopoverPosition.js';import useClickOutside from '../../hooks/useClickOutside';import useEscapeKey from '../../hooks/useEscapeKey';+import useFocusTrap from '../../hooks/useFocusTrap.js';import { tokenizeQuery, matchHaystack } from '../../lib/mediaSearch.js';import { isLaunchableTuiProvider } from '../../utils/providers';@@ -82,7 +83,14 @@ export default function ShellProviderLauncher({ providers, onLaunch, onOpen, loa// container — a single-ref containment check would read every click inside// the panel (including typing in the filter) as an outside click.useClickOutside([containerRef, popoverRef], open, close);- useEscapeKey(open, close);+ // Escape returns focus to the trigger explicitly: Safari does not focus a+ // button on click, so the trap's captured opener can be <body>.+ useEscapeKey(open, () => { close(); triggerRef.current?.focus(); });+ // The panel is portaled to the end of <body>, so without this Tab from the+ // trigger skips it. Waits for the measured `style` (the panel is hidden until+ // then, and a hidden element cannot take focus). Moves focus in on open, wraps Tab inside, and returns+ // focus to the trigger on close (Escape, pick, or outside click).+ useFocusTrap(open && !!style, popoverRef);const toggle = () => {if (open) { close(); return; }@@ -103,6 +111,7 @@ export default function ShellProviderLauncher({ providers, onLaunch, onOpen, loaclassName="flex items-center gap-1.5 px-2.5 py-1.5 bg-port-card hover:bg-port-border text-gray-300 hover:text-white rounded text-xs transition-colors border border-port-border min-h-[40px] shrink-0"title="Launch an AI CLI from your enabled providers"aria-label="Launch an AI CLI"+ aria-haspopup="true"aria-expanded={open}><Bot size={14} />@@ -124,8 +133,8 @@ export default function ShellProviderLauncher({ providers, onLaunch, onOpen, loa>{launchable.length >= FILTER_THRESHOLD && (// Sticky so the filter stays reachable while scrolling a long list.- // Deliberately not autofocused — on a phone that pops the keyboard- // over the very list the user opened the menu to look at.+ // Focus lands here on open (useFocusTrap) so keyboard users can type+ // straight away.<div className="sticky top-0 flex items-center gap-2 px-3 py-2 bg-port-card border-b border-port-border"><Search size={14} className="text-gray-500 shrink-0" /><inputdiff --git a/client/src/components/shell/ShellProviderLauncher.test.jsx b/client/src/components/shell/ShellProviderLauncher.test.jsxindex 123e235934..04eddede7d 100644--- a/client/src/components/shell/ShellProviderLauncher.test.jsx+++ b/client/src/components/shell/ShellProviderLauncher.test.jsx@@ -134,4 +134,16 @@ describe('ShellProviderLauncher', () => {fireEvent.keyDown(window, { key: 'Escape' });expect(screen.queryByText('Claude Code TUI')).toBeNull();});++ it("exposes popup state, moves focus into the panel, and returns it to the trigger on Escape", () => {+ open();+ const trigger = screen.getByLabelText("Launch an AI CLI");+ expect(trigger.getAttribute("aria-haspopup")).toBe("true");+ expect(trigger.getAttribute("aria-expanded")).toBe("true");+ expect(document.activeElement).toBe(screen.getByText("Claude Code TUI").closest("button"));++ fireEvent.keyDown(window, { key: "Escape" });+ expect(trigger.getAttribute("aria-expanded")).toBe("false");+ expect(document.activeElement).toBe(trigger);+ });});diff --git a/client/src/hooks/useFocusTrap.js b/client/src/hooks/useFocusTrap.jsindex bee276d4f4..edfa5bdde0 100644--- a/client/src/hooks/useFocusTrap.js+++ b/client/src/hooks/useFocusTrap.js@@ -151,7 +151,9 @@ export default function useFocusTrap(active, containerRef, { initialFocusRef } =}// Restore focus to the pre-open element so keyboard users return to where// they were. Guard: it may have been removed from the DOM while open.- if (previouslyFocused && typeof previouslyFocused.focus === 'function') {+ // <body> is not a real target (nothing was focused at open) — focusing it+ // would blur whatever the caller just moved focus to, e.g. a trigger.+ if (previouslyFocused && previouslyFocused !== document.body && typeof previouslyFocused.focus === 'function') {previouslyFocused.focus();}};