Skip to content

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

address review (codex): hand focus to the toast when the pill is expanded by keyboard

[._.]/ Adam Eivy24f865cbaa8f
diff --git a/client/src/components/ui/Toast.jsx b/client/src/components/ui/Toast.jsx
index b89b3b9615..7d1ee9f825 100644
--- a/client/src/components/ui/Toast.jsx
+++ b/client/src/components/ui/Toast.jsx
@@ -10,7 +10,7 @@
* own dismiss timer passes `collapseAfter` to fold on its schedule instead.
*/
-import { useState, useEffect } from 'react';
+import { useState, useEffect, useRef } from 'react';
import { uuidv4 } from '../../lib/uuid.js';
let toasts = [];
@@ -210,6 +210,27 @@ function ToastItem({ t, toastOptions }) {
const isCollapsed = collapsed && collapsible;
const bodyStyle = isCollapsed ? { ...style, display: 'none' } : style;
+ // Expanding the pill unmounts the pill. If the keyboard had focus on it,
+ // focus falls to <body> and the toast's own Reconcile/Reload/Ignore buttons
+ // 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.
+ const bodyRef = useRef(null);
+ const refocusOnExpand = useRef(false);
+
+ useEffect(() => {
+ if (isCollapsed || !refocusOnExpand.current) return;
+ refocusOnExpand.current = false;
+ // Runs after commit, so the body is no longer `display: none` and can
+ // actually take focus.
+ bodyRef.current?.focus();
+ }, [isCollapsed]);
+
return (
<>
{isCollapsed && (
@@ -222,7 +243,10 @@ function ToastItem({ t, toastOptions }) {
// folds it away again on its own.
<button
type="button"
- onClick={() => setCollapsed(false)}
+ onClick={e => {
+ refocusOnExpand.current = e.currentTarget === document.activeElement;
+ setCollapsed(false);
+ }}
aria-label={collapsedLabel(t)}
className="pointer-events-auto flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-port-card border border-port-border shadow-lg text-sm"
>
@@ -230,7 +254,12 @@ function ToastItem({ t, toastOptions }) {
</button>
)}
<div
+ ref={bodyRef}
style={bodyStyle}
+ // Focusable only programmatically (see the refocus effect); -1 keeps
+ // the body itself out of the tab sequence so it never sits between the
+ // page's own controls.
+ tabIndex={-1}
role={t.type === 'error' ? 'alert' : 'status'}
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
diff --git a/client/src/components/ui/Toast.test.jsx b/client/src/components/ui/Toast.test.jsx
index 393e7dd902..ff805da766 100644
--- a/client/src/components/ui/Toast.test.jsx
+++ b/client/src/components/ui/Toast.test.jsx
@@ -143,6 +143,42 @@ describe('long-lived toasts stop blocking the page', () => {
expect(screen.queryByRole('button', { name: /show notification/i })).toBeNull();
});
+ it('moves focus into the toast when the pill is expanded from the keyboard', () => {
+ act(() => {
+ toast(() => <button type="button">Reconcile</button>, {
+ duration: Infinity,
+ label: 'Install out of sync',
+ });
+ });
+ advance(COLLAPSE_AFTER_MS);
+
+ // Activating the pill unmounts it. Without a handover focus lands on
+ // <body> and the toast's own buttons leave the tab sequence entirely.
+ const pill = screen.getByRole('button', { name: /show notification/i });
+ pill.focus();
+ fireEvent.click(pill);
+
+ const body = screen.getByRole('status');
+ expect(document.activeElement).toBe(body);
+ expect(document.activeElement).not.toBe(document.body);
+ // ...and the toast stays put while it holds focus.
+ advance(COLLAPSE_AFTER_MS * 2);
+ expect(screen.getByRole('button', { name: 'Reconcile' })).toBeVisible();
+ });
+
+ 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 }));
+
+ expect(document.activeElement).toBe(document.body);
+ advance(COLLAPSE_AFTER_MS);
+ expect(screen.getByRole('button', { name: 'Show notification: Build is stale' })).toBeVisible();
+ });
+
it('keeps focus held even after the pointer sweeps over the toast and leaves', () => {
// Hover and focus are independent holds. A single shared flag lets the
// pointer leaving release a hold that focus still owns, and the collapse