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: keep keyboard focus within notifications and restore the bell (#6913)

[._.]/ Adam Eivyb1d4874f7cbe
diff --git a/client/src/components/NotificationDropdown.jsx b/client/src/components/NotificationDropdown.jsx
index c5f06ef6ae..77cd59a0e0 100644
--- a/client/src/components/NotificationDropdown.jsx
+++ b/client/src/components/NotificationDropdown.jsx
@@ -4,6 +4,7 @@ import { useNavigate } from 'react-router';
import { Bell, X, CheckCheck, Trash2, Brain, ListTodo, AlertTriangle, Code, HelpCircle, BellRing, Sparkles } from 'lucide-react';
import { timeAgo } from '../utils/formatters';
import { isHttpUrl } from '../utils/urlNormalize';
+import useFocusTrap from '../hooks/useFocusTrap.js';
import useClickOutside from '../hooks/useClickOutside.js';
import usePopoverPosition, { VIEWPORT_PADDING } from '../hooks/usePopoverPosition.js';
@@ -89,6 +90,9 @@ export default function NotificationDropdown({
contentDeps: [showAll, notifications.length]
});
+ // Wait until positioning makes the portal visible before moving focus into it.
+ useFocusTrap(isOpen && !!panelStyle, popoverRef);
+
// 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));
@@ -129,7 +133,11 @@ export default function NotificationDropdown({
{/* Bell button with badge */}
<button
ref={triggerRef}
- onClick={() => setIsOpen(!isOpen)}
+ onClick={() => {
+ // Pointer activation does not focus buttons in every browser.
+ triggerRef.current?.focus();
+ setIsOpen(!isOpen);
+ }}
className="relative inline-flex items-center justify-center min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 sm:p-2 rounded-lg hover:bg-port-card transition-colors focus:outline-hidden focus:ring-2 focus:ring-port-accent focus:ring-offset-2 focus:ring-offset-port-bg"
title="Notifications"
aria-label={`Notifications${unreadCount > 0 ? ` (${unreadCount} unread)` : ''}`}
@@ -182,8 +190,7 @@ export default function NotificationDropdown({
<Trash2 className="w-4 h-4 text-gray-400" aria-hidden="true" />
</button>
)}
- {/* Touch has no Escape key, and a tall panel can be clamped over the
- bell, so mobile needs an explicit dismiss it can always reach. */}
+ {/* Keep a dismiss target available even when the notification list is empty. */}
<button
type="button"
onClick={() => setIsOpen(false)}
diff --git a/client/src/components/NotificationDropdown.test.jsx b/client/src/components/NotificationDropdown.test.jsx
index 2fc13eb324..34c8c54895 100644
--- a/client/src/components/NotificationDropdown.test.jsx
+++ b/client/src/components/NotificationDropdown.test.jsx
@@ -1,5 +1,6 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import { MemoryRouter, useLocation } from 'react-router';
import NotificationDropdown from './NotificationDropdown';
@@ -121,6 +122,44 @@ describe('NotificationDropdown', () => {
});
});
+ it('enters the visible panel and cycles keyboard focus within its actions', async () => {
+ const user = userEvent.setup();
+ renderDropdown();
+ const bell = screen.getByRole('button', { name: /^Notifications/ });
+ bell.focus();
+ await user.keyboard('{Enter}');
+ const first = screen.getByRole('button', { name: 'Mark all notifications as read' });
+ const last = screen.getByRole('button', { name: 'Mark notification as read: Notification 2' });
+ expect(first).toHaveFocus();
+
+ await user.tab({ shift: true });
+ expect(last).toHaveFocus();
+ await user.tab();
+ expect(first).toHaveFocus();
+ await user.tab();
+ expect(screen.getByRole('button', { name: 'Clear all notifications' })).toHaveFocus();
+ await user.keyboard('{Escape}');
+ expect(queryPanel()).toBeNull();
+ expect(bell).toHaveFocus();
+ });
+
+ it('keeps an empty panel keyboard accessible on repeated opens', async () => {
+ const user = userEvent.setup();
+ renderDropdown({ notifications: [] });
+ for (let i = 0; i < 2; i += 1) {
+ openPanel();
+ const close = screen.getByRole('button', { name: 'Close notifications' });
+ expect(close).toHaveFocus();
+ await user.tab();
+ expect(close).toHaveFocus();
+ await user.tab({ shift: true });
+ expect(close).toHaveFocus();
+ await user.keyboard('{Enter}');
+ expect(queryPanel()).toBeNull();
+ expect(screen.getByRole('button', { name: /^Notifications/ })).toHaveFocus();
+ }
+ });
+
describe('dismissal', () => {
it('closes on Escape', () => {
renderDropdown();
@@ -129,6 +168,7 @@ describe('NotificationDropdown', () => {
fireEvent.keyDown(document, { key: 'Escape' });
expect(queryPanel()).toBeNull();
+ expect(screen.getByRole('button', { name: /^Notifications/ })).toHaveFocus();
});
it('closes on an outside click but not on a click inside the portaled panel', () => {
@@ -144,15 +184,15 @@ describe('NotificationDropdown', () => {
expect(queryPanel()).toBeNull();
});
- it('offers a close control below sm, where there is no Escape key', () => {
+ it('offers a close control and restores focus to the bell', () => {
renderDropdown();
openPanel();
const close = screen.getByRole('button', { name: 'Close notifications' });
- expect(close.className).toContain('sm:hidden');
fireEvent.click(close);
expect(queryPanel()).toBeNull();
+ expect(screen.getByRole('button', { name: /^Notifications/ })).toHaveFocus();
});
});