Notifications
diff --git a/frontend/js/notifications.js b/frontend/js/notifications.js
index db3f1fa..5ce49f7 100644
--- a/frontend/js/notifications.js
+++ b/frontend/js/notifications.js
@@ -158,6 +158,16 @@ export async function skipMessage(id, btn) {
await api(`/api/messages/${encodeURIComponent(id)}/read`, 'POST')
.catch(e => console.warn('[bell] skip (mark-read) failed', id, e));
await loadUnreadMessages(true); // panel still open: the next one is shown
+ if (!btn.isConnected) _focusPanel(); // the list was redrawn: Skip is gone, focus would fall to
+}
+
+// Keyboard users: the panel precedes the bell in the DOM, so opening it left
+// focus on the bell with the panel's buttons behind it. Land on the first
+// action, or on the close button when the list is empty.
+function _focusPanel() {
+ const p = document.getElementById('msg-panel');
+ if (!p?.classList.contains('open')) return;
+ (p.querySelector('#msg-list button') || p.querySelector('.mp-header button'))?.focus();
}
export function toggleMsgPanel() {
@@ -168,7 +178,7 @@ export function toggleMsgPanel() {
// Refresh on open so the list is never the boot-time snapshot — shadow
// principles land in the background long after the page loaded.
if (opening) {
- loadUnreadMessages(true);
+ loadUnreadMessages(true).then(_focusPanel);
_armPanelClose();
}
}
diff --git a/tests/test_a11y_nav.py b/tests/test_a11y_nav.py
index 5336edd..105f0f9 100644
--- a/tests/test_a11y_nav.py
+++ b/tests/test_a11y_nav.py
@@ -498,6 +498,47 @@ def test_setup_connect_redraws_keep_focus():
out.get("drawn") == 1 and out.get("focusedId") == want)
+# ── 7. the bell panel takes focus when opened and keeps it after Skip ───────
+
+def test_bell_panel_focus():
+ """#msg-panel precedes #msg-bell in the DOM and nothing moved focus, so a
+ keyboard user who opened it stayed on the bell with the Respond/Skip
+ buttons behind them; Skip then redrew the list and focus fell to
+ (WCAG 2.4.3). The panel is a labelled region, opening focuses its first
+ action, and a redraw after Skip refocuses."""
+ check("panel is a labelled region",
+ re.search(r'
({name, isConnected: conn, focus() { focused = name; }, setAttribute() {}, textContent: '', disabled: false});
+let listBtn = mk('respond', true), closeBtn = mk('close', true);
+const panel = {classList: {contains: () => open, toggle() { open = !open; }},
+ querySelector: s => s === '#msg-list button' ? listBtn : closeBtn};
+globalThis.document = {getElementById: id => id === 'msg-panel' ? panel : id === 'msg-bell' ? mk('bell', true) : null};
+const api = async () => ({}), encodeURIComponent = x => x, _armPanelClose = () => {};
+async function loadUnreadMessages() { return; }
+%s
+(async () => {
+ toggleMsgPanel(); await new Promise(r => setTimeout(r, 0));
+ const afterOpen = focused;
+ listBtn = null; focused = null; // empty list: close button
+ await _focusPanel(); const empty = focused;
+ listBtn = mk('next', true); focused = null;
+ await skipMessage(1, mk('skip', false)); const gone = focused; // pressed button was redrawn away
+ focused = null;
+ await skipMessage(1, mk('skip', true)); const kept = focused; // still in the DOM: leave focus alone
+ console.log(JSON.stringify({afterOpen, empty, gone, kept}));
+})();
+""" % fns) if fns.strip() else {}
+ if out is not None:
+ check("opening focuses the first action", out.get("afterOpen") == "respond")
+ check("empty panel focuses the close button", out.get("empty") == "close")
+ check("Skip redraw refocuses the panel", out.get("gone") == "next")
+ check("Skip leaves focus alone when its button survives", out.get("kept") is None)
+
+
if __name__ == "__main__":
for name, fn in list(globals().items()):
if name.startswith("test_") and callable(fn):