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

fix: retain notification focus after clearing or removing actions (#6913)

[._.]/ Adam Eivy1e8414d81432
diff --git a/client/src/components/NotificationDropdown.jsx b/client/src/components/NotificationDropdown.jsx
index 77cd59a0e0..f3128eaf86 100644
--- a/client/src/components/NotificationDropdown.jsx
+++ b/client/src/components/NotificationDropdown.jsx
@@ -73,6 +73,7 @@ export default function NotificationDropdown({
const [isOpen, setIsOpen] = useState(false);
const [showAll, setShowAll] = useState(false);
const containerRef = useRef(null);
+ const closeRef = useRef(null);
const navigate = useNavigate();
// The panel is portaled to <body> and placed in viewport coordinates. That is
@@ -93,6 +94,14 @@ export default function NotificationDropdown({
// Wait until positioning makes the portal visible before moving focus into it.
useFocusTrap(isOpen && !!panelStyle, popoverRef);
+ // Read/remove/clear and expansion can unmount the focused action. Keep the
+ // next Tab inside the panel by moving to its persistent dismiss control.
+ useEffect(() => {
+ if (isOpen && panelStyle && document.activeElement === document.body) {
+ closeRef.current?.focus();
+ }
+ }, [isOpen, panelStyle, notifications, unreadCount, showAll]);
+
// Both refs: the panel lives outside the trigger's subtree once portaled, so a
// trigger-only containment check would read clicks on the panel as outside.
useClickOutside([containerRef, popoverRef], isOpen, () => setIsOpen(false));
@@ -193,6 +202,7 @@ export default function NotificationDropdown({
{/* Keep a dismiss target available even when the notification list is empty. */}
<button
type="button"
+ ref={closeRef}
onClick={() => setIsOpen(false)}
className="inline-flex items-center justify-center min-w-[44px] min-h-[44px] rounded hover:bg-port-border transition-colors focus:outline-hidden focus:ring-2 focus:ring-port-accent sm:hidden"
title="Close"
diff --git a/client/src/components/NotificationDropdown.test.jsx b/client/src/components/NotificationDropdown.test.jsx
index 34c8c54895..8a39d1991b 100644
--- a/client/src/components/NotificationDropdown.test.jsx
+++ b/client/src/components/NotificationDropdown.test.jsx
@@ -1,3 +1,4 @@
+import { useState } from 'react';
import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
@@ -160,6 +161,36 @@ describe('NotificationDropdown', () => {
}
});
+ it('retains panel focus when updates remove the focused action', async () => {
+ const user = userEvent.setup();
+ function LiveDropdown() {
+ const [notifications, setNotifications] = useState(makeNotifications(2));
+ return (
+ <NotificationDropdown
+ notifications={notifications}
+ unreadCount={notifications.filter(n => !n.read).length}
+ onMarkAllAsRead={() => setNotifications(items => items.map(n => ({ ...n, read: true })))}
+ onRemove={id => setNotifications(items => items.filter(n => n.id !== id))}
+ onClearAll={() => setNotifications([])}
+ />
+ );
+ }
+ render(<MemoryRouter><LiveDropdown /></MemoryRouter>);
+ openPanel();
+ await user.keyboard('{Enter}');
+ const close = screen.getByRole('button', { name: 'Close notifications' });
+ expect(close).toHaveFocus();
+
+ await user.click(screen.getByRole('button', { name: 'Remove notification: Notification 0' }));
+ expect(close).toHaveFocus();
+ await user.click(screen.getByRole('button', { name: 'Clear all notifications' }));
+ expect(close).toHaveFocus();
+ await user.tab();
+ expect(close).toHaveFocus();
+ await user.tab({ shift: true });
+ expect(close).toHaveFocus();
+ });
+
describe('dismissal', () => {
it('closes on Escape', () => {
renderDropdown();