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(toast): detect keyboard pill activation by detail===0, not activeElement
[._.]/ Adam Eivy7afe8af89dfd
diff --git a/client/src/components/ui/Toast.jsx b/client/src/components/ui/Toast.jsxindex 7d1ee9f825..d336594473 100644--- a/client/src/components/ui/Toast.jsx+++ b/client/src/components/ui/Toast.jsx@@ -215,11 +215,17 @@ function ToastItem({ t, toastOptions }) {// drop out of the tab sequence — the next Tab restarts from the top of the// document, past everything. So hand focus to the body it just revealed.//- // Only when the pill actually held focus. A pointer activation in an engine- // that doesn't focus buttons on click has nothing to rescue, and moving focus- // there anyway would take the focus hold and pin the toast open until the- // user clicked elsewhere — turning a click of curiosity back into the- // parked overlay this all exists to remove.+ // Only for a KEYBOARD activation, detected by `detail === 0` — the click a+ // browser synthesizes from Enter/Space carries no click count, while a real+ // pointer click carries at least 1. `document.activeElement === the pill` is+ // NOT a usable substitute: Chrome focuses a button on mouse-down, so it reads+ // true for an ordinary click. Measured in headless Chrome against the running+ // page, that mis-detection moved focus into the body on a plain mouse click,+ // `onFocus` took the focus hold, and the toast never folded again — the exact+ // parked overlay this file exists to remove, handed back to the mouse users+ // who reported it. jsdom hides this: `fireEvent.click` doesn't focus the+ // button, so an activeElement-based guard passes the unit test and fails the+ // browser. The tests below therefore pass `detail` explicitly.const bodyRef = useRef(null);const refocusOnExpand = useRef(false);@@ -244,7 +250,7 @@ function ToastItem({ t, toastOptions }) {<buttontype="button"onClick={e => {- refocusOnExpand.current = e.currentTarget === document.activeElement;+ refocusOnExpand.current = e.detail === 0;setCollapsed(false);}}aria-label={collapsedLabel(t)}diff --git a/client/src/components/ui/Toast.test.jsx b/client/src/components/ui/Toast.test.jsxindex ff805da766..b019b371cc 100644--- a/client/src/components/ui/Toast.test.jsx+++ b/client/src/components/ui/Toast.test.jsx@@ -106,7 +106,11 @@ describe('long-lived toasts stop blocking the page', () => {act(() => { toast('New build available', { duration: Infinity }); });advance(COLLAPSE_AFTER_MS);- fireEvent.click(screen.getByRole('button', { name: /show notification/i }));+ // `detail: 1` marks this a pointer/touch activation. Say it explicitly:+ // jsdom defaults `detail` to 0, which the component reads as a KEYBOARD+ // activation and answers by taking focus — so a bare `fireEvent.click`+ // here would silently test the wrong gesture and fail.+ fireEvent.click(screen.getByRole('button', { name: /show notification/i }), { detail: 1 });expect(screen.getByRole('status')).toBeVisible();// No pinning on expand — a tap on a touch device (no mouseleave ever@@ -154,9 +158,11 @@ describe('long-lived toasts stop blocking the page', () => {// Activating the pill unmounts it. Without a handover focus lands on// <body> and the toast's own buttons leave the tab sequence entirely.+ // `detail: 0` is what makes this a KEYBOARD activation — the browser+ // synthesizes Enter/Space clicks with no click count.const pill = screen.getByRole('button', { name: /show notification/i });pill.focus();- fireEvent.click(pill);+ fireEvent.click(pill, { detail: 0 });const body = screen.getByRole('status');expect(document.activeElement).toBe(body);@@ -167,14 +173,26 @@ describe('long-lived toasts stop blocking the page', () => {});it('does not steal focus when the pill is expanded by pointer', () => {- // Nothing to rescue, and taking focus here would pin the toast open until- // the user clicked elsewhere — back to a parked overlay.act(() => { toast('Build is stale', { duration: Infinity }); });advance(COLLAPSE_AFTER_MS);- fireEvent.click(screen.getByRole('button', { name: /show notification/i }));+ // Model what a real browser does, or this test proves nothing: Chrome+ // FOCUSES a <button> on mouse-down, so `document.activeElement` is the pill+ // for an ordinary click too — a guard written against it reads "keyboard"+ // here and steals focus. jsdom's bare `fireEvent.click` neither focuses the+ // button nor sets `detail`, which is how an activeElement-based guard+ // passed this test while parking the toast open forever in Chrome (measured+ // via CDP against the live page). So focus the pill AND send `detail: 1`.+ const pill = screen.getByRole('button', { name: /show notification/i });+ pill.focus();+ fireEvent.click(pill, { detail: 1 });++ // Focus must NOT have been handed to the body: `onFocus` there takes the+ // focus hold, and nothing would ever release it.+ expect(document.activeElement).not.toBe(screen.getByRole('status'));- expect(document.activeElement).toBe(document.body);+ // The invariant that actually matters — no expand path may leave the toast+ // parked. Whatever the activation, it folds itself away again.advance(COLLAPSE_AFTER_MS);expect(screen.getByRole('button', { name: 'Show notification: Build is stale' })).toBeVisible();});